Adsense After The First Post In Wordpress

Written by Joe on September 17, 2007 – 3:22 pm -

Google Adsense LogoOn 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 | 39 Comments »

39 Responses to “Adsense After The First Post In Wordpress”

  1. BlogMasterPg Says:

    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).

  2. Passitnow Admin Says:

    Wow. Thanks a lots.. This is working on my site…Thankx again… !!!

  3. Fortyniner Says:

    Hej there,

    how can I put an ad after post 2,4, and 6.

    i already tried

    but it doesn’t work :-(

  4. musictoad Says:

    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?

  5. Joe Says:

    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.

  6. nick Says:

    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.

  7. Joe Says:

    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.

  8. Mohan Says:

    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 :)

  9. StartupSideline.com Says:

    Props Joe, I got it working! Thanks for the tip.

  10. EroSan Says:

    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.

  11. Show AdSense Ads After First or Every Post in Wordpress Blogs [How-To] | Welcome To Devils Workshop Says:

    [...] Based on Joe Hayes post. [...]

  12. tony Says:

    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!

  13. Adsense Beast Says:

    contact me on my site to get a FREE AdSense ready site like myne

  14. Mauricio Says:

    Thank you very much… You saved my day…

  15. Marie Says:

    This is great. I used the same principle to get it at the bottom of a single post too.

  16. VUhoops.com Says:

    THANK YOU. I have been trying for weeks trying different code changes… this FINALLY did it!

  17. Derek Pollard Says:

    Many thanks, this is exactly what I was looking for. Updating the template only took a minute.

  18. Place AdBrite ads below your first blog post in Wordpress (works also with Google AdSense) | The Ultimate Business Book Says:

    [...] to Joe Hayes for his simple [...]

  19. Dimitar Nikolov Says:

    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:

  20. Antique Ring Says:

    I usually do not comment on blog posts but I found this quite interesting, so here goes. Thanks! Regards, P.

  21. ApocD Says:

    Great information here. I put the code on my site and it worked just as I wanted. Thanks a lot.

  22. Janel Fradette Says:

    Hello to all :) I cant understand how to add your site in my rss reader. Help me, please

  23. Joko Susilo Says:

    Thanks for sharing. Salam ACTION! :)

  24. Richard Says:

    Please let me know if you would like to exchange link with a pr 4 blog, thanks!

  25. elaine Says:

    Thanks for the tip, it works great!

  26. Maria Says:

    i am just starting out with Google Adsense. i am hoping that i would earn a good deal of money on this program.

  27. wayangtimes Says:

    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 :)

  28. Durkin Says:

    Worked great, thanks very much!

  29. acnecare Says:

    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.

  30. melatoninplus Says:

    i really love Google Adsense. i could earn a decent amount of cash with this make money online program from Google.

  31. Joint88 Says:

    Adsense is my main source of income when making money online. nothing beats adsense when it comes to making money online.

  32. Webmaster Blog – Science of the Web | Action Webmasters Says:

    [...] 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 [...]

  33. Anna Lea Says:

    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.

  34. Cathryn Says:

    i use Adsense on my blogs and websites, i can say that Adsense is the best make money online program on the internet.

  35. Jainee Says:

    i love Google Adsense, it allows me to make money on my personal blog and some of my health related sites.

  36. Andrian Says:

    Great, it’s work! Thank you!

  37. Caramoan Tour Package Blog Says:

    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.
    `

  38. michael Says:

    It works, thank you very much!

  39. Ernie Says:

    Thanks for the info, worked on my blog.

Leave a Reply