Title: Jetpack Infinite Scroll &#8211; Insert ad code every 6th post?
Last modified: August 20, 2016

---

# Jetpack Infinite Scroll – Insert ad code every 6th post?

 *  Resolved [Antigrav](https://wordpress.org/support/users/antigrav/)
 * (@antigrav)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/jetpack-infinite-scroll-insert-ad-code-every-6th-post/)
 * I’ve been able to get this to work on the first loop of 6 posts, but subsequent
   blocks of posts that come in via infinite scroll do not have the ad in place.
 * I’ve been using the following:
 * Before Loop:
 *     ```
       <?php $countpost = 0; ?>
       ```
   
 * With this added into the content loop:
 *     ```
       <?php if ( (is_archive() or is_page() or is_search() or is_home()) && ($countpost == 6) ) : ?>
   
       AD CODE HERE
   
       <?php
       endif;
       $countpost++;
       ?>
       ```
   
 * My content loop (without the code above) is:
 *     ```
       <div id="content">
   
       		<?php /* Start the Loop */ ?>
   
       		<?php while ( have_posts() ) : the_post(); ?>
   
       			<?php get_template_part( 'content', get_post_format() ); ?>
   
       		<?php endwhile; // end of the loop. ?>
       ```
   
 * [http://wordpress.org/extend/plugins/jetpack/](http://wordpress.org/extend/plugins/jetpack/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [13 years, 3 months ago](https://wordpress.org/support/topic/jetpack-infinite-scroll-insert-ad-code-every-6th-post/#post-3528752)
 * To insert Javascript once the posts were added by Infinite Scroll, you can follow
   the recommendations in our support documentation:
    [http://jetpack.me/support/infinite-scroll/#javascript-events](http://jetpack.me/support/infinite-scroll/#javascript-events)

Viewing 1 replies (of 1 total)

The topic ‘Jetpack Infinite Scroll – Insert ad code every 6th post?’ is closed to
new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

## Tags

 * [insert ads](https://wordpress.org/support/topic-tag/insert-ads/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/jetpack-infinite-scroll-insert-ad-code-every-6th-post/#post-3528752)
 * Status: resolved