Add-ons /

Next Page

Developer documentation for the Ajax Load More Next Page add-on.


Filter Hooks

The following filter hooks are available when using this add-on:

alm_nextpage_break_{id}

The alm_nextpage_break filter will automatically split the content of the post into pages without requiring the Page Break block or <!–-nextpage–-> quicktag inserted into the content.

The following code snippet will dynamically page the content of each post wherever an <h2/> element is found – view example.


function alm_nextpage_autosplit(){ 
   // [ajax_load_more id="autosplit" nextpage="true"]
   return '<h2>';
}
add_filter('alm_nextpage_break_autosplit', 'alm_nextpage_autosplit');
PHP

alm_nextpage_the_content

The alm_nextpage_the_content filter provides a method to modify the content of the current page.

The following code snippet will prepend an <h3/> with the current page number to the content of each page.

function my_nextpage_content( $content, $page ) {
   $content = "<h3>Page: ${page}</h3>" . $content;
   return $content;
}
add_filter( 'alm_nextpage_the_content', 'my_nextpage_content', 10, 2 );
PHP

alm_nextpage_paged

Do not load previous pages when a user enters via deep link URL. e.g. https://e.g.website.com/about/4/

// e.g.website.com/about/4/
add_filter( 'alm_nextpage_paged', function(){
	return false;
});
PHP

alm_nextpage_leading_slash

Add a leading slash / before the page number in the URL.

add_filter( 'alm_nextpage_leading_slash', '__return_true' );
PHP

Note: This is useful when permalink URLs do not have trailing slashes.

alm_nextpage_remove_trailing_slash

Removes the trailing slash / from the end of the URL.

add_filter( 'alm_nextpage_remove_trailing_slash', '__return_true' );
PHP

alm_nextpage_before

Used to render content before a page is displayed. In this example, a Google Adsense advertisement will be displayed at the opening of each page load.

function alm_nextpage_before($page){
   // $page = The current page number
   $html = '<ins class="adsbygoogle"
		style="display:block"
		data-ad-client="ca-pub-{ID}"
		data-ad-slot="{SLOT}"
		data-ad-format="auto"></ins>	
	<script>
	    (adsbygoogle = window.adsbygoogle || []).push({});
	</script>';	
   return $html;
}
add_filter('alm_nextpage_before', 'alm_nextpage_before', 10, 2);
PHP
function alm_nextpage_before( $page ) {
	if ( $page === 2 ) {
		$html = '<p>This is page #2</p>';
		return $html;
	}
}
add_filter( 'alm_nextpage_before', 'alm_nextpage_before', 10, 2 );
PHP

alm_nextpage_after

Used to render content after a page is displayed. In this example, text copy will be displayed after each page.

function alm_nextpage_after($page){ 
   // $page = The current page number
   $html = '<p>Continue reading below...</p>';	
   return $html;
}
add_filter( 'alm_nextpage_after', 'alm_nextpage_after', 10, 2 );
PHP

Frequently Asked Questions

Below are common questions regarding the Next Page add-on. If you have a question and don’t see an answer here, please visit the support page and submit your request.


« Back to Add-ons