[Support request] Reload ads with infinite scroll

Home Forums Support [Support request] Reload ads with infinite scroll

Home Forums Support Reload ads with infinite scroll

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #790595
    Ernesto Justiniano

    Hi, how can I reload the ads between posts when using infinite scroll?

    #791183
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    How are you inserting the ads in the first place?

    Let me know 🙂

    #791324
    Ernesto Justiniano

    Hi, this code is working but not with infinite scroll, see please below:

    /////////////////////////
    // in functions.php or in plugin:

    <script async=’async’ src=’https://www.googletagservices.com/tag/js/gpt.js’></script&gt;
    <script>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    </script>

    /////////////////////////////////////
    //****** edited index.php with

    $post_counter=1;
    if ( have_posts() ) :

    while ( have_posts() ) : the_post();

    get_template_part( ‘content’, get_post_format() );
    $post_counter++;

    if ($post_counter == 2 || $post_counter == 6){
    get_template_part( ‘ads’, get_post_format() ); // see below ads.php
    }

    endwhile;

    ////////////////////////
    //****where ads.php contains:

    $adId = ‘div-gpt-ad-‘ . rand();
    ?>
    <article id=”post-<?php the_ID(); ?>” <?php post_class(); ?> <?php generate_do_microdata( ‘article’ ); ?>>

    <script async=’async’ src=’https://www.googletagservices.com/tag/js/gpt.js’></script&gt;
    <script>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    </script>

    <script>
    googletag.cmd.push(function() {
    googletag.defineSlot(‘/30089507/GH1’, [[300, 250], [970, 250], [300, 90], [320, 90], [274, 228], [728, 90], [336, 280], [274, 90]], ‘<?php echo $adId ?>’).setTargeting(“test”,”infinitescroll”).addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.pubads().collapseEmptyDivs();
    googletag.enableServices();
    });
    </script>

    <!– /30089507/GH1 –>

    ‘ style=”text-align:center;clear:both”>
    <script>
    googletag.cmd.push(function() { googletag.display(‘<?php echo $adId ?>’); });
    </script>

    </article>

    #791452
    Tom
    Lead Developer
    Lead Developer

    Just looked into this and I’m not sure if it’s possible, unfortunately.

    Here’s something I found: https://stackoverflow.com/questions/22658484/how-to-display-more-than-four-adsense-units-for-an-infinite-scrolling-page

    #791499
    Ernesto Justiniano

    Do you know how can I edit the infinite_scroll’s callback function? If I can call some scripts after every load the problem is resolved as I do use DFP.

    #791505
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.