Contents
I’ve been using Genesis for quite a while and till just a few hours ago, I didn’t know I could actually do away with the “Post Layout” plugin I’ve been using to add Google ads and other codes to properly format my post pages. Over the last few weeks, I’ve been trying to reduce my number of installed plugins in order to decrease page load time and also CPU usage. From disabling StatPress, Auto Excerpt Everywhere, down to Social Author bio and loads of other plugins, I thought it would be a good idea to use Genesis Hooks and some conditional statements to display ads and other codes instead of relying a third-party plugin I didn’t really need.
Finally, I was able to display the ads and other stuffs just the way I wanted it and right now, I’m using Genesis hooks to display everything you see above and below posts. As a matter of fact, it rather fun digging into the code side of things… got to learn more WordPress conditional statements (I never really did care because I didn’t know how useful they were).
We’re adding these adsense codes or custom PHP / HTML in five positions in this tutorial, it’s up to you to choose where you want your stuffs to appear:
1. The sidebar
2. Below the header
3. Below post title
4. After post content
5. Above posts in archive pages
Well, I’m not sure I need to explain this but for beginners, you only need to go to Appearance > Widgets. Drag the text widget to your desired location and paste the ad code or custom HTML. That’s it.
2. Adding Google Adsense below the header
I already explained this in a previous post but this is going to be a bit advanced. For someone like me who has a skycrapper on the sidebar and two ad units on post pages, I would like hide that leaderboard below the menu on post pages. This is where conditional statements come in; you only need to add a snippet of code to tell the advert not to appear on single posts and pages.
– Download and install Simple Genesis Hooks
– Go to Genesis > Simple Hooks
– Scroll down till you get to the content section
– In the box labelled genesis_before_content_sidebar_wrap
Hook, paste this code:
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>
– Be sure to mark Execute Shortcodes on this hook
and Execute PHP on this hook
The part in red is the conditional statement that tells the ad not to appear on single posts and pages. So, this appears on the home page and all archive pages and with this implemented the right way, you won’t be having more than three ad units on each of your site pages. You can even take this further if you’ve done PHP programming or any sort of programming before. It’ll be much more easier for you to manipulate this statements and make your ads appear exactly where you want them to be.
3. Below post title
Now we’re going to add adsense below post title and we’re still gonna use Simple Hooks and conditional statements. The first time I did this, the Google Adsense ads appeared on archive pages and the home page till I added a statement that forced the ads to appear on single posts and pages only.
– Go to Genesis Simple hooks settings page and find genesis_before_post_content
Hook. If you’re using a HTML5 theme and you can’t find that, search for this instead: genesis_entry_header
– In the box, paste this code:
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>
– Also, mark Execute Shortcodes on this hook
and Execute PHP on this hook
The part in red tells the advert to appear on single posts or pages. It’s gonna be hidden from the homepage and archive pages and I’m sure you don’t wanna show it there, do you?
Is the post info getting in the way? Install Genesis Simple Edits plugin and check the settings. Cut what you have as the Post Info and save the page.
Now paste what you cut from Simple Edits above your advert in Genesis Simple Hooks
4. After post content
You’re still using the same code you used right above but you’re only going to add it to a different position, OK?
– Search for genesis_after_post_content Hook
. If you’re using a HTML5 theme and you can’t find that, locate this instead: genesis_entry_footer
– Paste the code up there in to the box and save.
Is the Post Meta (categories and tags) getting in the way? Install Genesis Simple Edits plugin and check the settings. Cut what you have as the Post Meta and save the page.
Now paste what you cut from Simple Edits below your advert in Genesis Simple Hooks.
5. Above posts in archive pages
Still tweaking the conditional statements, we can make ads appear on archive pages only. This include category pages, tag pages, author pages and so on.
To make ads appear directly above posts on archive pages:
– go to Genesis Simple Hooks settings page and search for genesis_before_loop
– Paste this
<div align="center" style="width:100%; padding:5px; background: #ffffff;">
YOUR ADSENSE CODE, AFFILIATE LINK OR BANNER HERE
</div>
<?php }?>
There are lots of other positions you can add your codes, you only need to study genesis hooks deeper and learn more about WordPress conditional tags. With this, you can show or hide ads or custom PHP / HTML where ever you want in your Genesis theme.