Blog Tip: Comply With Google AdSense Restrictions On Your WordPress Index Page
Google's "AdSense for Content" policies restrict every page on your blog to three ad units, three link units, three referral units and two search boxes (see Google AdSense Program Policies). Many of you place at least one ad unit in the content section of each article. On the index page (the home page) it's a good idea to place a single ad on three individual articles instead of multiple ads on one article.
How do you comply with the restrictions if you're displaying more than three articles on your index page? The answer lies in editing the theme. Yes, there are plugins that will insert your code into specific places in your theme. At least one of them purports to limit the ad units to three on the index page, but I never tested it to find out. Editing the relevant part of the theme is easy. You only need to concern yourself with the index.php file. The instructions that follow are the way I control my ad placements on the index page.
You start by placing your AdSense code where you want it to display, the best place being between the post title and the content. Once you have it in place, insert this code just before the beginning "<script" line:
<?php
$gcount++; // google post counter
if ($gadv < 3) { // how many ads to display?
if ($gcount%1 == 0) { // display ad after how many posts?
$gadv++; // count number of advertisements
print '
Then after the "</script>" of the final line of the code:
';
}
}
?>
After you get it set up properly, it doesn't matter if you display three or ten articles on the index page. Only the first three will only have ad units on them. If you need help with your theme, feel free to send me a message via my contact page.
This is not the only way to control ad placement on the index page. I recommend you read Darren Rowse's article, "Introduction to Advertising Optimization – Ad Position", and Aaron Brazelle's article, "How to: Placing Adsense Strategically Between Posts".
Thanks to Matthew of eJabs for sending me the code a few months ago.
(Update 2007-08-11: I now use the Shylock Adsense Plugin to do the dirty work for me. I made one change to the plugin to make it work with certain kinds of posts but other than that, it does the job.)
Similar Posts:



I use the AdSense Deluxe plugin on all my blogs that use AdSense. I have never had a problem.
How many articles are on the front page and how many have AdSense on them?
Never mind. I just looked at your main site. AdSense Deluxe, back when I tried to use it, wouldn't work on my theme correctly for some reason.
It doesn't matter. I have a firm grasp on the internal workings of WordPress themes now.
What did you say RT? I didn't get that, but when you talk this deep I never do. Just couldn't resist.
Someday, Sandee, when you finally get tired of dealing with blogger and decide to self-host a WordPress domain, you'll be digging through all this stuff…
I've never had an issue with it. It's always just stopped displaying ads when it exceeds 3 ads. Not sure why, but I figured this was done on their part as it seems easy enough for them.
I've seen some blogs where the 4th and subsequent ads are repeated and some where they're blank. Why take chances?
Oh absolutely, no reason to risk it if it's happening. I just can't figure out why it's never been an issue for our site.
Are you using a plugin for it or did you put it in manually like I did?
I wondered why you could never get more than three ads in Blogspot – now I know.
Great tip. As a recent Adsense user myself, I found out this little compliance aspect I wasn't aware of. I kind of did something similar in my theme code to control the number of ads to 3.
Between you have given some nice links to intro articles that is now in my reading list.
Thanks RT!
I'm glad you like them!
[...] Blog Tip: Comply With Google AdSense Restrictions On Your WordPress Index Page by RT Cunningham [...]
Great. What took you so long to tell us that?
Thanks.
Thanks for this post… I found you through ProBlogger where my post on blogging tips
made it to the list
Hmm great tip.. But will it work for all themes?
Some days ago I was trying to put only one add unit on index page in post content. I did it through placing the adsense code in theme index.php page but it was showing three add units in three posts on index page.
I will try this code to see if I can restrict it to one.
The 3rd line of the code controls that. Change "< 3" to "< 1" and you'll only get one ad.
Great tip. Thanks a lot
[...] Blog Tip: Comply With Google AdSense Restrictions On Your WordPress Index Page by RT Cunningham [...]
I didn't know google adsense restricted to 3 ad units. weird.
I am experimenting with the skylock plugin to delay ads, so far it has worked great. This tip would still work well for those that want to keep things simple and not use yet another plugin!
That's why I wrote it. For the simplicity of it.
I'm switching one of my sites over to adbrite and this code made the page not render at all.
You have to watch the single quotes and double quotes. If the script has single quotes, change them to double or it won't work. I haven't seen adbrite's code, but I'd be willing to bet that's why.
I've been searching high and low for a method to do exactly this. I didn't like the big gaps the empty ads left, and this is a simple way to remove them.
Dan's last blog post..Review
Hey Great info . I gather some very informative bloggin adsense
Rob's last blog post..G Lock Blog Finder
To solve this problem I personally use Semiologic – I think Denis Bernardy did a great job in his latest version of WordPress based solution, because the ad management got super easy – simple drag and drop.
I was afraid that in case you edit the one post template (in Semiologic) it will put AdSenses at the top of each post, so that on the index page of my blog I would have 10 adsense blocks.
No! It worked around it. So, guys and gals, my advice is to also use Semiologic to comply with AdSense policy on blogs.
I don't do it manually anymore. I use "Who See's Ads". The Semiologic plugin is a good choice too.
I wrote some code myself to use on blog but yours has an option to mention where to display ads and where not. Good work buddy.!
Flashy Flashy's last blog post..Post title, archive page title optimization in blogger (blogspot subdomains)
That saved me from a major headache. Thanks.
SAVED ME A BUNCH OF TIME!!! CHEERS
Good article about google AdSense. This helped me a lot to understand Google AdSense. I found another site about AdSense certpaper dot com.