How to Insert Adsense Ads Between Posts in WordPress Blogs

How can you insert Adsense ads between posts on WordPress archives, categories, tags,  index, search and homepages. As you learnt about how to insert Adsense inside articles, inserting between WordPress post summary pages is a little different.

Insert Ads Between Posts in Archives

While editing your WordPress theme appearance, open index.php or archive.php. These files control the theme template for the homepage, index pages and archive pages (category and tags). The secret is to insert the Adsense code as seen on our site is below.

<?php $postnum++; if($postnum%5 == 0) { ?>
.responsive { width: 300px; height: 250px; }
@media(min-width: 500px) { .responsive { width: 336px; height: 280px; } }
<ins class="adsbygoogle yourclass"
(adsbygoogle = window.adsbygoogle || []).push({});
<?php } ?>

This code uses Adsense responsive unit to show small and large rectangle ads depending on the screen size. I had told you this large rectangle ad setting is the highest paying combination to target both 300x250px and 336x280px ads.

Add Adsense loader script once

It is best to load Adsense script once. You can place it between the <HEAD> tags of your html code, such that it loads only once for multiple ad units. Since it uses asynchronous adsense code, it does not slow page loading time and can be used at the top the code.

<script async src="//"></script>

Posts Per Page

The important thing to note here is you need to check how many post summaries you display on each category, tag or index pages. This can be done via Settings > Reading

archive posts number

So you can choose how many post summaries to display on any such archive page. This example displays 8 post summaries on each page.

Display Multiple Adsense Ads

With code setting at $postnum%5, it will insert an Adsense ad after every 5 posts. So if you have 8 posts displayed, it will display the ad only once on this page. Now it is your choice how many ads you want to display on a page. Note you cannot display more than 3 ad units per page.

If you increase the posts per page to lets say 12, then this will display 2 ads, one after the 5 th post and one after the 10th post. Alternatively you can change the count code to  $postnum%3, which will cause the ads to load after 3 ads and so on.

Here is how it will look like.

adsense middle ads


  1. MichaelSeguin says:

    it’s really such a nice design collection , its give me new more ideas and we are also from same industry and welcome you to visit our site.

  2. Sid Jobs says:

    Helpful post on adsense basics. Much appreciated.


  3. Golam Rabbani says:

    Really your post very important for newbie.many persons trying to add Adsense add in there wordpress blog.If we follow your post then we can do it easily.Thank you for sharing this good tips with us.

  4. Ukrainian says:

    That`s the one I was seeking for. Thanks a lot! It is very light and easy to implement and maintain. And there is a tendency to minimization and adaptive design so Adsense now can keep the pace on our sites :)

  5. Rajib Mondol says:

    At first you have to create a lot of post on your own wordpress site. The topics which you will post that will have to useful for the people. If you have create a lot of useful topics then everybody will go to your site. Your site will be high PR site and get Google AdSense.

  6. GokartsWiz says:

    I agree, Its important to locate the ads correctly to attract clicks from readers. Nice detailed writeup.

  7. raja says:

    woww…..thanx for sharing this superb post nafter following your instruction now i am able to add adds on my post.

  8. WNG Sodashop says:

    This is the ultimate guide for the beginners. There is know doubt that wordpress is the most popular platform for the blog hence everyone should need such kind of tips especially if they intended to earn money from adsense.

  9. Mich says:

    I was just looking for this to implement on my wordpress blog.Thanks for this.

  10. Arpit Roy says:

    Was browsing a few sites and stumbled here – No Regrets ! Thanks for sharing this.

  11. andy says:

    i highly recommend added line breaks (2) before and after your ads so it doesn’t junk up your content.

  12. Fahim Zada says:

    Any trick for approval of addsense ?

  13. Baba Vanga says:

    Thanks Chandra for sharing the script how to insert adsense in between posts. To make it even easier – I use the google adsense free plug-in that does exactly the same thing. You can point where exactly your ads will appear – in the header, sidebar, footer, first paragraph, second paragraph…etc. Also you can switch between page and post – so you might have one placement of the adsense code for all posts, and a totally different placent of the code for all pages. It’s really handy – have been using it for a while. Anyways, thanks for sharing man – and keep up this informative blog!


  14. Masukur Rahman says:

    Hi Chandra,
    Publishing ads between posts helps to earn more revenues from adsense and i think, your post helps to earn more revenues from adsense. Recently i am searching about these and finally i get this on your blog.

Leave a Reply

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