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.

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) { ?>
<style>
.responsive { width: 300px; height: 250px; }
@media(min-width: 500px) { .responsive { width: 336px; height: 280px; } }
</style>
<ins class="adsbygoogle yourclass"
style="display:inline-block"
data-ad-client="ca-pub-12345678"
data-ad-slot="12345678"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php } ?>

This code use 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.

So where is the Adsense loader script? 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="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

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


Share:

Free Email Newsletter

Get every new tip we post in your email.
11,000 subscribers and growing...

Recommended for you »

13 Responses

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

    Thanks!

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

  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!

    Cheers

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Free Email Newsletter

Get every new tip we post in your email.
11,000 subscribers and growing...