• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Nile Flores Media

Helping You Rock Out Your Website Like A Rockstar

  • Home
  • About
  • Blog
  • Portfolio
  • Hire Me
  • Resources
  • Contact
  • Blogging
  • WordPress
  • Social Media
  • SEO
  • Web Design
  • News
  • Podcast
You are here: Home » WordPress » Inserting Adsense Between Posts in WordPress

Inserting Adsense Between Posts in WordPress

By Nile Flores 35 Comments


There have been a few tutorials out there for inserting Google Adsense between posts, but a lot of them no longer work. Users have a lot of choices in Adsense plugins to insert their code within posts, sidebars, or main banner images.

However, inserting between posts, say the 4th and 5th post is not as easy and there are no plugins available. I have had clients who have asked this to be done, so here is a nifty little code snippet to add Adsense to your theme.

1. Open your index.php. Find the place in your WordPress loop after the_content or the_excerpt (depending on how your theme is coded) and before the PHP endwhile function.

2. Copy the following code

<?php if (++$PostCount == 4) {?>
<!-- Insert Adsense Code Here -->
<?php } ?>
<?php $postcount++; ?>

3. Insert your Adsense code in place to the line asking you to add you adsense code.

Simple, huh?

Well, somewhat. You can adjust the 4 in the code snippet to another number if you wish. Also, if you need to tweak the position of your Adsense, you can insert HTML code. The code uses the WordPress post count to count the posts and insert the code where you want it to be.

Please make sure when using the code to take in consideration Google’s policy on inserting their service into your site.


Filed Under: WordPress Tagged With: google adsense, wordpress, wordpress tricks

About Nile Flores

Nile is a 43-year old female from the greater St. Louis (Southern Illinois side) area. Nile is a mother of 1 son. She is also a web designer and developer, a graphic designer, and a public speaker, who exclusively designs and develops using WordPress. She also blogs at GoDaddy's Blog, Verpex Hosting's blog and her very personal sites, Pixelled and Nail Polish Happy.




Related posts:

Edit The Number Of Words For The Excerpt in WordPress How to Change The WordPress Default Avatar Applying Author Gravatar In Post Comments Display First WordPress Full Entry and then Following as Excerpts Brand Your WordPress Login Page Without A Plugin

Reader Interactions

Comments

  1. Marios Alexandrou says

    November 26, 2011 at 6:06 pm

    Check out the Ad Injection plugin. It gives you a bunch of options for inserting ads in the body content including after certain number of characters or paragraphs. You can also have it change the insertion point randomly. It’s pretty handy for testing out different insertion points without the need to modify theme files.

    Reply
  2. Anonymous says

    November 26, 2011 at 6:31 pm

    Ok, i wanna try it to my blog, i hope i can get more income from Google Adsense…
    thanks for tutorial..

    Reply
  3. marquita herald says

    November 26, 2011 at 7:10 pm

    Great tip – you have a very attractive site!

    Reply
  4. Anok says

    November 27, 2011 at 12:56 am

    ya, putting adsense just below title has a good CTR 🙂

    but how do we add adsense just after the 1st paragraph of every post?

    Reply
    • Nile says

      November 27, 2011 at 2:17 pm

      In blogspot, I am not too sure. In a self-hosted WordPress installation, there are plugins that you can specify where you want an ad to show up in an individual post.

      Reply
  5. James Hussey says

    November 27, 2011 at 1:58 am

    Great idea! Actually could you just use any banner besides AdSense? I don’t use AdSense myself, I prefer affiliate marketing.

    I may use this on my other blogs – right now I have the Flexsqueeze theme so it’s all ready to rock with ads as it is, but I still like the simplicity of your solution here.

    I DO have lots to learn about coding, that’s for sure…

    Reply
    • Nile says

      November 27, 2011 at 2:14 pm

      Yes, you should be able to put other banners too, whether your own in-house banner ads, or other systems.

      Reply
  6. Raj says

    November 27, 2011 at 4:19 am

    I guess this applies to the homepage. I have seen Blogger blogs that have done this, but I must say it was not a pretty sight! I guess it could be useful on the category pages, etc.

    Reply
  7. Herbert says

    November 27, 2011 at 4:23 am

    Wow!! This is what I need.. I have been looking for this one over and over again but can’t find any.. Thanks a lot Niles 😀 This makes my day complete

    Reply
  8. Herbert says

    November 27, 2011 at 4:24 am

    I will be back to confirm if everything works well 🙂

    Reply
    • Nile says

      November 27, 2011 at 2:15 pm

      It should, I am using it here. 🙂

      Reply
      • Herbert says

        November 28, 2011 at 8:35 am

        Hi Niles, 🙁 sad to say it didnt, I cant find that code in index.php but instead on the on the single.php file. I have inserted it but still it didnt work.. I will give it a try again within the week maybe I placed it incorrectly

        Reply
        • Nile says

          November 28, 2011 at 10:11 am

          You should be putting it into the index.php or home.php, not the single.php theme file.

          Reply
  9. ioana moise says

    November 27, 2011 at 5:04 am

    Amazing trick for putting adsense in wordpress i will also use on my wordpress

    Reply
  10. David says

    November 27, 2011 at 12:37 pm

    Thanks. Having ads between posts improves chances of getting clicks!

    Reply
  11. Beth Hewitt says

    November 27, 2011 at 3:02 pm

    Hey Nile,

    It’s a pleasure to finally find you 🙂

    This is invaluable information. I look forwarded to reading some of more of your posts.

    To Your Success,
    Beth 🙂

    Reply
  12. Kevin Schmidt says

    November 27, 2011 at 5:16 pm

    awesome trick!
    Thanks for sharing that 🙂
    Also, I really like the look of your site… very cool!
    -Kevin

    Reply
  13. saba says

    November 27, 2011 at 8:50 pm

    Thank you, I am trying to help my sister fix up her blog, and been looking for this code for a while. will give it a go.

    Cheers
    Saba

    Reply
  14. Nick says

    November 27, 2011 at 9:45 pm

    I have never thought about having Adsense ads between post. Time to test! I wonder what the click through rate will be like. Hopefully, a few percentages higher.

    Reply
  15. Richard says

    November 27, 2011 at 11:41 pm

    This a very informative article to read. Providing us useful tips and refreshing information is a big help to us . I will definitely try this on my blog. And i will follow all the instruction that you have mentioned in this article. Thanks!

    Reply
  16. David Cornick says

    November 28, 2011 at 1:26 am

    So this is how to do it! So easy and it works.I have been trying for ages with plugin’s to insert Adsens ads between my earlier posts Thankyou

    Reply
  17. Erica says

    November 28, 2011 at 3:10 am

    Great tutorial! Thanks for sharing this and let me try it on my site as well!

    Reply
  18. Michael says

    November 28, 2011 at 5:20 am

    Hi Nile,

    Brilliant trick! I’m always discovering cool little tricks to use within word press. This only adds to that long list.

    Thanks again! 🙂

    Michael

    Reply
  19. kayus says

    November 28, 2011 at 8:41 am

    Gee! thnaks for giving this code here.i would copy and past into my theme.but the way to go about this in the theme is somewhat confusing to me.

    Anyway it is useful.

    Reply
    • Nile says

      November 28, 2011 at 10:16 am

      This is a WordPress tutorial. It will not work in Blogger.

      Reply
  20. Mark says

    November 28, 2011 at 9:14 am

    Informative post…With out using any plugins it would be great

    Reply
  21. Alex says

    November 28, 2011 at 11:39 am

    Oh I did this so many times in my blog post and sometimes it doesn’t work well, but it helps you get traffic much….

    Reply
  22. Katie Woodard says

    November 28, 2011 at 1:36 pm

    I have a suggestion as well. Couldn’t you just put an ad at the end of every fourth or fifth ad to acomplish the same thing.

    Reply
  23. Anonymous says

    November 29, 2011 at 1:03 pm

    is this how i would start to make money off my blog? Currently I blog because i enjoy talking about certain subjects. Are you saying that if I followed your steps above that i could generate revenue from my blog? great!

    Reply
  24. matt says

    December 1, 2011 at 7:25 am

    Before I’m using adsense optimizer plugin but I remove it on my blog. With that plugin I can easily insert advertisement in between post but in my case It doesn’t have that much effect or low conversion rate. But that is only in my case I don’t know with the others who have tried it.

    Reply
  25. Ankit says

    December 18, 2011 at 12:08 pm

    Nice post, helped me a lot to place adsense on my blog. I have one question that how can I increase my CPC in adsense, coz as far as my ad placements are concerned my CTR goes to ~4-1% but my CPC is quiet low.
    Any tips to improve it??

    Reply
  26. Itender Rawat says

    January 29, 2012 at 3:30 am

    Thanks Admin. I was looking for this from 2 days. Its a real helpful for me.

    Reply
  27. Dipendra says

    March 6, 2012 at 3:20 pm

    This is the best placement I earn from Adsense.

    Reply
  28. Schalk says

    April 11, 2012 at 5:36 pm

    Hi

    Osim post, simple and exactly what i was looking for, thanx!

    But now I need to take it one step further, I also want to add some adsense code after post number 8.

    I thought I can just duplicated the code, replacing the 4 with an 8, but no luck.

    Thanx

    Reply
  29. Krypto Mehedi says

    December 12, 2014 at 1:17 am

    Hello Nile, I am not expert at coding. So, i just use some plugin that integrates adsense code to my post,title and others place.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow Me On:

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Get The Latest WordPress & Blogging Tips

Sign up for my newsletter, and also get my free ebook on 10 Reasons Why Your Website Isn't Converting, and How to Fix it!




Try to be More Positive on Social Media

Note: You can click on image and view the video in a larger lightbox window.

Footer

The Blog

Lots of free information, tutorials, and more to help you bring your best foot forward with your website.

  • Blogging
  • WordPress
  • Social Media
  • SEO
  • Web Design

Get The Latest WordPress & Blogging Tips

Sign up for my newsletter, and also get my free ebook on 10 Reasons Why Your Website Isn't Converting, and How to Fix it!

Copyright © 2025 · · WordPress