Question from Harlan F.: I have a problem Rick, and I’m really hoping you can help me solve it.
I have a WordPress blog that uses the Genesis Framework and the Genesis Simple Hooks plugin to display ads on my blog. I pasted my Adsense code into the genesis_after_content
hook in order to have an ad displayed at the end of every post (and page).
It works great, but the problem is it also displays an ad after every post snippet on the home page. As you probably know, this is a big no-no since Google limits us to three Adsense ads per page.
My question is how can I get Simple Hooks to display an Adsense ad at the end of each post without also displaying them on the home page?
Rick’s answer: You’re right about the Adsense program’s three ads per page rule Harlan, and you’re wise to avoid going over that amount. Luckily, it’s very easy to have the Genesis Simple Hooks plugin place your ads only on individual posts and pages. Here’s all you have to do:
1 – As before, find the genesis_after_content
hook and paste in your Adsense code.
2 – Paste this code snippet on a blank line immediately before the beginning of the Adsense code:
<?php if(is_singular()) { ?>
3 – Paste this code snippet on a blank line immediately after the end of the Adsense code:
<?php } ?>
The code inside the box should now look like this:
<?php if(is_singular()) { ?>
<p>your-adsense-code-here</p>
<?php } ?>
4 – Check the box beside “Execute PHP on this hook?”.
5 – Click the Save Changes button.
From now on you should see an Adsense ad displayed after each post and on every page. But you should not see them on the home page, the category pages, or any other pages that display multiple posts.
Do you have a tech question of your own for Rick? Click here and send it in!