How to Insert AdSense Ads Between Posts in WordPress Archives

Your homepage, category, tag and search pages list many post summaries, and the space between them is a natural place for an ad. Here’s how to insert AdSense ads between posts in WordPress archive pages: with a few lines in your theme template, with a plugin, or automatically with Auto ads. This is different from inserting AdSense inside articles, because archive pages loop through many posts.

Quick answer: In your theme’s archive template (index.php, archive.php or the loop template part), add a check inside the WordPress loop such as if ( ( $wp_query->current_post + 1 ) % 4 === 0 ) and output your AdSense ad code there. That shows an ad after every 4th post. Or use the Advanced Ads or Ad Inserter plugin, or AdSense In-feed ads and Auto ads, without touching code.

Method 1: Insert AdSense ads between posts with code

Open your (child) theme’s archive template. Depending on the theme, the loop is in index.php, archive.php, home.php, or a template part like template-parts/content.php. Inside the loop, after each post summary, add:

<?php if ( ( $wp_query->current_post + 1 ) % 4 === 0 && ! $wp_query->is_singular() ) : ?>
  <div class="archive-ad">
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-XXXXXXXXXXXXXXXX"
         data-ad-slot="1234567890"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
  </div>
<?php endif; ?>

Replace the client and slot IDs with your own from your AdSense account (Ads > By ad unit). $wp_query->current_post starts at 0, so adding 1 and checking % 4 inserts an ad after posts 4, 8, 12 and so on. Change 4 to place ads more or less often.

In the original version of this tutorial we used a manual $postnum++ counter and a fixed 300×250 / 336×280 ad. Today a responsive ad unit adapts to every screen, and WordPress’s built-in loop counter is simpler.

Add the AdSense script once

Load the AdSense script just once in your site’s <head>, not with every ad. That’s faster, as we explained in load the AdSense script once for multiple ads:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX" crossorigin="anonymous"></script>

It’s asynchronous, so it doesn’t block your page from loading.

Check how many posts appear per page

Go to Settings > Reading and check Blog pages show at most. With 8 posts per page and an ad every 4 posts, you get 2 ads per page.

WordPress posts per page setting

Here’s how ads between posts looked on our archive pages:

AdSense ads between posts in WordPress archives

AdSense used to limit you to three ad units per page. That rule was removed in 2016, but Google still requires that ads don’t outweigh your content, so keep a sensible balance.

Method 2: Use a plugin (no code)

  • Advanced Ads: create an ad, then choose the Post lists placement and the position (for example, after the 4th post).
  • Ad Inserter: has a Between posts insertion option with paragraph and post counters.

Plugins survive theme changes, which is a big advantage over editing templates.

Method 3: AdSense In-feed ads and Auto ads

AdSense offers In-feed ads, designed to blend into lists of articles: create one under Ads > By ad unit > In-feed ads and use it in place of a display ad above. Or turn on AdSense Auto ads, which automatically places ads on archive pages too. We use Auto ads on this site.

Tips

  • Keep ad slots a fixed minimum height with CSS to avoid layout shift as ads load.
  • Don’t place ads where they could be mistaken for post links, which breaks AdSense policies.
  • Hide unfilled slots cleanly; here’s how to hide unfilled AdSense ad spaces.

Frequently asked questions

Is there still a limit of three AdSense ads per page?

No. Google removed the three-ad limit in 2016. Instead, ads mustn’t exceed your content on the page.

Will these ads show on single posts?

No. The code runs only in archive loops. The is_singular() check makes sure of it.

Do In-feed ads earn more than display ads?

It varies. In-feed ads match your post list style, which can improve clicks on archive pages. Test both and compare RPM.

Stuck on a gift? Try our free Gift Idea GeneratorIdeas for anyone by age, job, interests and budget, with Amazon.com and Amazon.in linksFind gifts →

Found this useful? Share it with someone who needs it.

Get our free weekly email: new tech guides and tools, no spam.

New and updated tech guides, a free tool worth bookmarking and one useful pick, once a week. No spam, unsubscribe anytime.

One email a week. Unsubscribe anytime. See our privacy policy.

Related Tech Guides

Leave a Reply

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

13 Comments

  1. 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.
    Thanks

  2. 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!

    Cheers

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

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

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

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

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

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

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

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