Ads in Infinite Scroll and Dynamically Loaded Content

By  Stephan Depta
Last updated November 16, 2026

Many sites load more posts while the visitor scrolls or after a click on “Load more”. Since AdPresso 1.7.0, your placements also work in this loaded content. New posts get their ads just like the posts that were on the page from the start. This is part of the free version of AdPresso.

With the plugins listed below it works without any setup. Themes and plugins that load content with their own script need a small integration, which the rest of this page describes.

Supported out of the box

Plugin or featureVersionSetup
Jetpack Infinite ScrollFreeNone. AdPresso detects it.
Ajax Load MoreFreeNone. AdPresso detects it.
BuddyPress activity streamsProNone.
PeepSo activity streamsProNone.

There is no setting for this in AdPresso. To check that it works, open a page with infinite scroll or a “Load more” button, load more posts, and look for your ads in the new posts.

Enable dynamic content support

The client scripts for dynamic content are only loaded when they are needed. The filter adpresso_dynamic_content_support switches them on for every page. It expects a boolean and defaults to false. Jetpack Infinite Scroll and Ajax Load More enable it on their own.

add_filter( 'adpresso_dynamic_content_support', '__return_true' );

JavaScript API

After your script has added new content to the page, tell AdPresso about it. There are two functions.

FunctionUse it when
AdPresso.content.scan( container )the new HTML is already in the DOM. AdPresso looks for placements inside the container and fills them.
AdPresso.content.insert( container, html, { view: 'new' } )you have the HTML as a string. AdPresso inserts it into the container and fills the placements in it.
fetch( url )
	.then( ( response ) => response.text() )
	.then( ( html ) => {
		const container = document.querySelector( '#more-posts' );
		container.insertAdjacentHTML( 'beforeend', html );
		AdPresso.content.scan( container );
	} );

Views: continue or new

Loaded content belongs to one of two views.

ViewMeaningSingle Appearance (Pro)
continue (default)The content extends what the visitor already sees, as in a stream or the next page of a list.Ads that were already shown stay blocked.
newThe content counts as a new page view, for example the next article loaded below the current one.Starts over.
  • Impressions are counted per inserted copy of an ad, in both views.
  • Content that is inserted into content loaded earlier takes over the view of that content when you use continue, not the view of the page.
  • Single Appearance shows an ad only once per view.

The adpresso:contentLoaded event

Instead of calling the functions directly, you can dispatch the event adpresso:contentLoaded. Its detail carries root, the element that contains the new content, and view, which is 'continue' by default or 'new'.

document.dispatchEvent(
	new CustomEvent( 'adpresso:contentLoaded', {
		detail: { root: container, view: 'continue' },
	} )
);

Content loaded before AdPresso is ready

If your script may run before AdPresso has loaded, push the content into the queue window.adpressoContentQueue. AdPresso processes the entries as soon as it is ready.

window.adpressoContentQueue = window.adpressoContentQueue || [];
window.adpressoContentQueue.push( { root: container, view: 'continue' } );

PHP helper for your own endpoints

If you render posts in your own AJAX or REST endpoint, wrap the rendering in adpresso_render_in_post_context(). The helper sets up the post context so that AdPresso can add its placements to the output. It is meant for REST and AJAX requests only. During a normal page view it returns an empty string and writes a “doing it wrong” notice to the debug log.

adpresso_render_in_post_context( $post, callable $callback, array $args = [] );
adpresso_render_in_post_context(
	$post,
	function () {
		get_template_part( 'template-parts/content', 'single' );
	},
	[ 'output' => 'js' ]
);
Value of outputResult
'js' (default)All placements come back as placeholders, and the browser selects the ads. The response can be cached.
'auto'Each placement decides, as in a normal page view, whether it is rendered on the server or in the browser. Server-rendered ads are part of the returned HTML. The response is specific to this request and not suited for caching without further measures.

How the two output paths differ is explained in The rendering pipeline. More hooks are listed under Filters.

Stephan Depta

About the Author

Stephan Depta is a software engineer and WordPress developer with more than 12 years of experience building plugins, web applications, and custom WordPress solutions. He worked on Advanced Ads for several years, first as Lead Developer and later as Product Manager, combining hands-on plugin development with software architecture, performance optimization, and technical product strategy. Today, he is one of the developers behind AdPresso, where he focuses on building fast, modern, and reliable ad management tools for WordPress publishers.

This is AdPresso

Streamlined WordPress ad management, built on 16+ years of expertise for serious monetization.
Features robust protection, targeting, A/B testing, diverse placements, and insightful tracking to spark your full revenue potential.

BlogStudies
AdPresso Logo