Title: Callback function &#8211; Ajax Auto Load Posts
Last modified: May 1, 2023

---

# Callback function – Ajax Auto Load Posts

 *  Resolved [mdotk](https://wordpress.org/support/users/mdotk/)
 * (@mdotk)
 * [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/)
 * I recently implemented auto load next posts with Ajax on the my site. Example:
   [https://connekthq.com/ajax-load-more-posts/alm-post-example/](https://connekthq.com/ajax-load-more-posts/alm-post-example/)(
   scroll down to the bottom).
 * Anyway, I have noticed that on my site (not the site above, which is the developer’s
   demo site) that embedded Web-Stories in the auto-loaded posts are not loaded.
   They need Javascript to be loaded, which is not being done (at present) on the
   auto-loaded posts.
 * However, the plugin I am using does have this however [https://connekthq.com/plugins/ajax-load-more/docs/callback-functions/almcomplete/](https://connekthq.com/plugins/ajax-load-more/docs/callback-functions/almcomplete/)
 * Can you tell me the function we could call in the almComplete callback to get
   my embedded web stories loading on auto-loaded posts too?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/#post-16703197)
 * Hi there
 * Can you perhaps elaborate on the “not loaded”. Are the plugin’s JS files loaded,
   but the stories themselves not visible? Or are not even the files loaded? And
   is this about the regular single embeds (using `<amp-story-player>`) or things
   like the carousel? A demo site or video/screenshot would be helpful to better
   understand the situation.
 * What I can say is that we don’t expose any global JS functions to just magically
   enqueue all required JS files or load stories via Ajax. So here’s a more general
   answer:
    - If the JS and CSS files for single embeds are missing, ensure the `standalone-
      amp-player` handles are enqueued (`https://cdn.ampproject.org/amp-story-player-
      v0.css` and `https://cdn.ampproject.org/amp-story-player-v0.js`)
    - If they are not missing, but the story in the amp-story-player is not loaded,
      you’ll need something like as follows to manually load them:
 *     ```wp-block-code
       document.querySelectorAll('amp-story-player').forEach(playerEl => (new AmpStoryPlayer(window, playerEl)).load())
       ```
   
 *  Thread Starter [mdotk](https://wordpress.org/support/users/mdotk/)
 * (@mdotk)
 * [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/#post-16705893)
 * Hi [@swissspidy](https://wordpress.org/support/users/swissspidy/) thanks so much.
   I filled in the web form with all the relevant info [https://docs.google.com/forms/d/e/1FAIpQLSd-AeFLOIJd4NLYz7EDUa9vMfzZIoT5Bn1leV3dL2CM_B1C6Q/viewform](https://docs.google.com/forms/d/e/1FAIpQLSd-AeFLOIJd4NLYz7EDUa9vMfzZIoT5Bn1leV3dL2CM_B1C6Q/viewform)
 * Thanks again!
 *  Plugin Author [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/#post-16706234)
 * OK, so the it’s the latter case for you. The scripts are already there, but the
   stories themselves in the player are not loaded because they were added later.
   So you’ll need something like the code I shared above.
 * Now, I don’t know this Ajax Load More plugin and how it works, so I can only 
   give you same minimum guidance. The rest is beyond our support offering for the
   Web Stories plugin.
 * You will want something like this:
    1. In the `almComplete` callback, access `alm.el` to get the newly added post.
    2. Find all `amp-story-player` instances within `alm.el`
    3. Load the players.
 * So, something like that:
 *     ```wp-block-code
       window.almComplete = function(alm){
       	alm.el.querySelectorAll('amp-story-player').forEach(
       		playerEl => (new AmpStoryPlayer(window, playerEl)).load()
       	);
       };
       ```
   
 * Again, I don’t know this Ajax Load More plugin, so I don’t know if this works.
 * If you need more help, I recommend asking on StackOverflow or similar.
 *  Thread Starter [mdotk](https://wordpress.org/support/users/mdotk/)
 * (@mdotk)
 * [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/#post-16708638)
 * Thank you [@swissspidy](https://wordpress.org/support/users/swissspidy/). I sincerely
   appreciate you going out of your way to assist me. The web-story plugin team 
   has the best support of any plugin I’ve used!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Callback function – Ajax Auto Load Posts’ is closed to new replies.

 * ![](https://ps.w.org/web-stories/assets/icon.svg?rev=2386543)
 * [Web Stories](https://wordpress.org/plugins/web-stories/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/web-stories/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/web-stories/)
 * [Active Topics](https://wordpress.org/support/plugin/web-stories/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/web-stories/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/web-stories/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [mdotk](https://wordpress.org/support/users/mdotk/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/callback-function-ajax-auto-load-posts/#post-16708638)
 * Status: resolved