Add-ons /

Single Posts

Developer documentation for the Ajax Load More Single Posts add-on.


Theme Templates

Some themes are more complicated than others with regards to implementing infinite scroll on single post templates.

To help you get started, we’re compiling a library of single.php examples for some popular WordPress themes and frameworks.

Note: You should always create a Child Theme before modifying core theme templates.


Filter Hooks

alm_single_posts_use_rest_api

This filter will disable the new REST API endpoint introduced in Single Posts v1.8 and fallback to using admin-ajax.php.

add_filter( 'alm_single_posts_use_rest_api', '__return_false' );
PHP

Callback Functions

almSinglePostsLoaded

The almSinglePostsLoaded() callback is dispatched after Single Posts has completed its initial setup routine on page load.

custom.js
window.almSinglePostsLoaded = function (alm) {
  console.log( 'ALM Single Posts Loaded' );
}
JavaScript

Custom Elements

Quite often, WordPress posts and pages include CSS and JS that are generated specifically for the current post — especially when using page builders or the block editor.

This can create issues when full articles are loaded via Ajax, because only a portion of the page is rendered on screen. As a result, some post-specific CSS or JS may be missing, leading to display or functionality problems.

To address this, the Single Posts add-on includes a feature that automatically detects and pulls any missing CSS and JS into the Ajax-loaded content.

The almSinglePostsCustomElements function provides functionality to specify an array of CSS and JS scripts to load with each article.


The code below instructs the plugin to look for enqueued CSS with the ID my-theme-inline-styles-css each time an article is loaded via Ajax. If the file is found, the CSS will be included with the loaded content, helping prevent any potential display issues.

// single.php
<script>
		window.almSinglePostsCustomElements = [	'#my-theme-inline-styles-css' ];
</script> 
PHP

This code should be added to the single.php template or wherever your Single Posts shortcode has been applied.

Note: The values in the array are the rendered IDs of each enqueued style or script.

<style id="my-theme-inline-styles-css">
	.post-198265 h2 {
	   font-weight: bold;
	   font-size: 30px;
	}
</style>
PHP

e.g. <style id="my-theme-inline-styles-css">...styles here</style>

// Generate Press
<script>
   window.almSinglePostsCustomElements = [
      '#generate-style-inline-css',
      '#generateblocks-inline-css',
      '#global-styles-inline-css'
   ];
</script>
PHP

Frequently Asked Questions

Below are common questions regarding the Single Posts 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