Title: Insert google dfp ads between every 5 posts using infinite scroll plugin
Last modified: August 22, 2016

---

# Insert google dfp ads between every 5 posts using infinite scroll plugin

 *  [kadiravan](https://wordpress.org/support/users/kadiravan/)
 * (@kadiravan)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/insert-google-dfp-ads-between-every-5-posts-using-infinite-scroll-plugin/)
 * Hi,
 *  I am having a wordpress site in which the frontpage posts are loaded using infinite
   scroll plugin [https://wordpress.org/plugins/infinite-scroll/](https://wordpress.org/plugins/infinite-scroll/)
   The page will have 8 ads and Now i am trying to insert google dfp ads between
   every 5 posts. I got the main loop to work but the real issue is that i have 
   to run an other counter to increment the google ads ID. Hence the first counter
   will insert the ads every 5 posts, and the next counter will increment the google
   ads id by 1 every time the loop is executed.
 *  ‘$count=0; $counter=0;
    if (($count>4) && ($count%5==0)){ $counter= $counter
   +1; ?> <div id=”adsbetween”> <div id=’div-gpt-ad-xxxx-<?php echo $counter; ?>’
   style=”width:300px; height:450px; display:inline-block; float:right;”> <script
   type=’text/javascript’> googletag.cmd.push(function() { googletag.display(‘div-
   gpt-ad-xxxx-<?php echo $counter; ?>’); }); </script> </div> </div> <?php }$count
   ++;’
 * In the above code, the same ad is inserted every time hence the ad doesn’t load.
   can you help me getting the counter value to increment by 1 each time?

The topic ‘Insert google dfp ads between every 5 posts using infinite scroll plugin’
is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [kadiravan](https://wordpress.org/support/users/kadiravan/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/insert-google-dfp-ads-between-every-5-posts-using-infinite-scroll-plugin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
