- This topic has 5 replies, 2 voices, and was last updated 4 years, 4 months ago by
Tom.
-
AuthorPosts
-
January 23, 2019 at 7:09 pm #790595
Ernesto Justiniano
Hi, how can I reload the ads between posts when using infinite scroll?
January 24, 2019 at 9:01 am #791183Tom
Lead DeveloperLead DeveloperHi there,
How are you inserting the ads in the first place?
Let me know 🙂
January 24, 2019 at 11:30 am #791324Ernesto 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>
<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>
<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>
January 24, 2019 at 3:06 pm #791452Tom
Lead DeveloperLead DeveloperJust 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
January 24, 2019 at 5:00 pm #791499Ernesto 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.
January 24, 2019 at 5:08 pm #791505Tom
Lead DeveloperLead Developer -
AuthorPosts
- You must be logged in to reply to this topic.