Adsense After The First Post In Wordpress
Written by Joe on September 17, 2007 – 3:22 pm -
On the homepage, one of the more effective places to implement Google Adsense is after the first post (same for any other archive type page, like the categories). While the CTR (click through rate) won’t be as high as placing the code above the first post, or after the first post title, it’s much cleaner and will provide a ‘less spammy’ place to put the code. Remember, folks are here for your content - not your ads.
At any rate, it’s pretty simple. You’ll need to use this code to prevent your ad code from appearing after every single post, as Wordpress would just loop and keep showing it (which would likely be against Google’s TOS as they only allow 3 ad blocks per page).
First, open your index.php (or home.php, archive.php, or any other file you want to do this for) and find this line:
<?php if (have_posts())
and before, add:
<?php $count = 1; ?>
This will be used to track which post is being displayed. Next we’re going to add the code to display your Adsense. Find:
<?php the_content
and after, add:
<?php if ($count == 1) : ?>
Adsense Code Goes Here
<?php endif; $count++; ?>
There you have it, quick and dirty. Remember, this has to go inside the loop otherwise it won’t display properly (place it before the <?php endif; ?> which closes the loop. If you wanted this outside the loop (completely before or completely after all your posts), there would be no need to iterate through a post count. You can change this code to display after any number of posts by changing the $count == 1 to whatever post number you’d like.
Posted in Monetization, Wordpress | 41 Comments »

September 26th, 2007 at 5:23 am
Right! If you go to see my blog i add the ad-sense ad after the first post; I choose image ads( I think there are better than text).
September 30th, 2007 at 11:50 pm
Wow. Thanks a lots.. This is working on my site…Thankx again… !!!
October 6th, 2007 at 10:58 am
Hej there,
how can I put an ad after post 2,4, and 6.
i already tried
but it doesn’t work
November 21st, 2007 at 1:09 pm
How to add it in Wordpress simple free account blog?
its MG or something with no FTP etc.
Again, how to add meta tage in this kind of wordpress blog?
February 6th, 2008 at 8:39 pm
Fortyniner, you could try using
< ?php if ($count == 2 || $count==4 || $count==6) : ?>musictoad, you’re going to have to talk to your blog hosting provider about that. It’s likely that unless they provide some sort of revenue sharing, widget control, or file editing.
March 3rd, 2008 at 7:08 am
I would like to have a banner ad from adsense below the first post, and also have 4 text link ads at the end of the first post before the comment and tags and what not. I know how to do either or using this technique, however when trying to implement both at the same time one of the two goes for multiple posts because of the nature of the code. I need to only have one of each only below the first post, as i use another adsense block in the sidebar, and I can only use a max of 3 adsense units per page as you know.
March 3rd, 2008 at 1:01 pm
Nick, two ways you can go about doing this (depending on your needs).
Method 1, use $count == 2 for the second instance of the code, because of the $count++ variable the second code block would be considered 2, regardless of whether it’s in the first post or not.
Method 2, remove the variable $count++; from the bottom of the first code block, and use $count == 1 for both blocks. After the second block executes, then the variable would increment.
April 15th, 2008 at 12:59 pm
Thanks for the tip Joe! I didn’t know PHP, so this came as a boon
BTW, tip for others…
If you want the ad to be displayed on the first 2 posts (or any other number), just edit the “== 1″ in the line
to the “< x” wherein ‘x’ is to be replaced by the the number of posts you want the ads to be displayed in plus one. i.e. If you want the ads to be displayed in the first 3 posts, use ‘< 4′.
I did
<?php if ($count
and have ads on after the 1st 2 posts
May 13th, 2008 at 12:17 am
Props Joe, I got it working! Thanks for the tip.
July 5th, 2008 at 10:19 pm
Man, I had read other tutorial and something was not working quite right. But after following your instructions, i finally got it working ^_^
Plus, im learning some basic php. Thanks.
July 10th, 2008 at 5:44 am
[...] Based on Joe Hayes post. [...]
July 20th, 2008 at 12:02 pm
doesn’t work on my site but that’s ok thanks anyway. it won’t be the first suggestion i have tried and it hasn’t worked. i’ve had problems with other suggestions, but i’ll keep looking!
August 8th, 2008 at 12:40 am
contact me on my site to get a FREE AdSense ready site like myne
August 27th, 2008 at 7:49 pm
Thank you very much… You saved my day…
August 28th, 2008 at 5:21 pm
This is great. I used the same principle to get it at the bottom of a single post too.
September 11th, 2008 at 6:07 pm
THANK YOU. I have been trying for weeks trying different code changes… this FINALLY did it!
October 9th, 2008 at 8:39 am
Many thanks, this is exactly what I was looking for. Updating the template only took a minute.
November 5th, 2008 at 12:07 pm
[...] to Joe Hayes for his simple [...]
March 8th, 2009 at 6:32 am
Thanks for the tip, Joe, it works perfectly on my blog.
To make the ads even more flexible, I have placed the AdSense code into a PHP file in the template directory and included with this tagline:
April 16th, 2009 at 8:03 pm
I usually do not comment on blog posts but I found this quite interesting, so here goes. Thanks! Regards, P.
April 18th, 2009 at 11:08 pm
Great information here. I put the code on my site and it worked just as I wanted. Thanks a lot.
April 27th, 2009 at 6:27 pm
Hello to all
I cant understand how to add your site in my rss reader. Help me, please
May 6th, 2009 at 5:30 am
Thanks for sharing. Salam ACTION!
July 7th, 2009 at 11:47 am
Please let me know if you would like to exchange link with a pr 4 blog, thanks!
July 14th, 2009 at 12:08 am
Thanks for the tip, it works great!
August 25th, 2009 at 3:32 am
i am just starting out with Google Adsense. i am hoping that i would earn a good deal of money on this program.
September 2nd, 2009 at 10:58 pm
hi thanks for the great tip. unfortunately it didn’t work on my blog. i think it got to do with the way my theme is coded. it’ll b nice if u can suggest some workaround solution pls? thanks
September 15th, 2009 at 6:43 am
Worked great, thanks very much!
September 25th, 2009 at 11:59 am
i am a beginner in monetizing my blog with Adsense. i still need to learn more about the tips and tricks on Adsense. hopefully i might be able to earn a decent amount of cash on Adsense.
September 28th, 2009 at 10:17 am
i really love Google Adsense. i could earn a decent amount of cash with this make money online program from Google.
October 13th, 2009 at 10:38 am
Adsense is my main source of income when making money online. nothing beats adsense when it comes to making money online.
October 19th, 2009 at 1:34 am
[...] is a webmaster blog which provides expert information about search engine optimization. Learn about Adsense in Wordpress to better monetize your sites. Visit us today! Link to this page Link to this page [...]
November 19th, 2009 at 11:30 am
Adsense is the best paying make money online program on the internet. I just wish that i could increase my website traffic to high levels so that i could earn more money on Adsense.
November 24th, 2009 at 3:29 am
i use Adsense on my blogs and websites, i can say that Adsense is the best make money online program on the internet.
November 29th, 2009 at 9:01 am
i love Google Adsense, it allows me to make money on my personal blog and some of my health related sites.
December 13th, 2009 at 10:30 am
Great, it’s work! Thank you!
December 24th, 2009 at 10:47 pm
I recently added an Adsense square ads on my travel blog. my adsense earning is still low since i dont have large volume of internet traffic yet.
`
January 12th, 2010 at 2:54 pm
It works, thank you very much!
January 16th, 2010 at 12:24 pm
Thanks for the info, worked on my blog.
February 14th, 2010 at 4:12 am
i am really very thankful that Google launched the Adsense program. this enables most of us who owns several websites to work at home.
March 4th, 2010 at 11:12 am
i love google Adsense, it enables me to earn money on the websites and forums that i have put up several years ago. if you got tons of websites, you can earn a lot from Adsense alone