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.


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 have CSS and JS created specifically for the current post. This is common with how content is created with page builders and the block editor.

This becomes an issue when loading entire articles with Ajax/JavaScript because only a portion of the loaded page is rendered to the screen, meaning some of the custom CSS and JS for that article could be left behind and cause display issues.

To get around this, the Single Posts add-on has a feature to pull 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 sample below instructs the plugin to look for an enqueued CSS file with the ID of my-theme-inline-styles-css with each Ajax-loaded article. If found, the CSS will be loaded along with the article and should resolve any 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