Docs    Facebook    Troubleshooting

My Facebook feed won’t load in an AJAX-enabled theme, page, form, or plugin

Themes and plugins that fetch content with AJAX can stop the feed script running. Why it happens and how to fix it.

Would you like to fix a Facebook feed that doesn’t show up when your theme, page, form, or plugin loads content with AJAX?

AJAX is a technique that gets content after your browser has already opened the page. Some themes use it to switch pages without a full reload. Some plugins use it for tabs or “infinite” loading. Some forms use it to show new content after a visitor submits them.

For a more complete explanation, see this article on AJAX from WPBeginner.

If your Facebook feed sits in a part of the page that loads this way, the feed may not show, or may not work properly. This guide gives you two fixes to try in order. It also tells you when to undo the first one.

Before you get started, make sure Facebook Feed is installed and activated on your WordPress site.

Turning On the AJAX Theme Loading Fix

To get started, we’ll turn on the setting that was made for this problem.

Facebook Feed has a setting called AJAX theme loading fix. It’s off by default. With it on, the plugin adds two small script tags to the feed’s own HTML. With it off, the plugin leaves them out.

Together, those tags load the plugin’s feed script with the feed. A feed that arrives through AJAX then brings its script with it. The setting’s help text also says it can work around JavaScript errors on the page.

  1. In the WordPress dashboard, go to Facebook Feed » Settings.
  2. Click the Advanced tab.
  3. In the AJAX theme loading fix box, turn on the toggle.
  4. Click Save Changes.

Next, open the page that has your feed and check whether the feed shows. If you use a caching plugin, clear its cache first so the page includes the new script tags. See How to Clear Your Cache in WordPress for a step-by-step guide.

If the feed still doesn’t load properly, move on to the next section.

Running the Feed Script From Your Theme or Plugin

Next, we’ll tell your theme or plugin to start the feed after it loads new content.

The first fix has a limit. If the page already has the plugin’s feed script, the script ignores the second copy. The feed inside the new content is then never set up.

To start it yourself, run the function cff_init after the new content loads. With no value passed in, it sets up every Facebook Feed on the page.

Themes and plugins that load content with AJAX often have a place for JavaScript that runs after new content loads. The name differs between themes and plugins. It is usually something like Custom JavaScript or Initialization JavaScript.

  1. In your theme or plugin’s settings, find the area for JavaScript that runs when new content loads.
  2. Add the line of code below to it.
  3. Save your changes. Then reload the page that has your feed.

Here’s the line to add in step two.

cff_init();

The line goes in your theme or plugin, not in the Custom JS field in Facebook Feed. That field is deprecated. For more on where your own JavaScript goes now, see our guide on moving custom JavaScript code out of our plugins.

If neither fix works, turn off the AJAX loading feature in your theme or plugin. You can also move the feed to a part of the page that loads with the page itself.

If the first fix caused new problems on your site, the next section shows you how to undo it.

When to Turn the Fix Off

The AJAX theme loading fix is one setting for your whole site. With it on, every feed on every page gets the extra script tags, including pages that don’t use AJAX.

On some sites, turning this setting on has caused two problems. The Load More button needed two clicks, or the same posts showed twice. If you see either one after turning the setting on, turn it off again.

  1. In the WordPress dashboard, go to Facebook Feed » Settings.
  2. Click the Advanced tab.
  3. In the AJAX theme loading fix box, turn off the toggle.
  4. Click Save Changes.

Then reload the page that has your feed. If you use a caching plugin, clear its cache first.

If you added the cff_init(); line, keep it in place. If you didn’t add it and the feed stops loading inside AJAX content, follow the steps in Running the Feed Script From Your Theme or Plugin.

That’s it! You now know how to get a feed to load inside AJAX content, and when to undo the first fix. If your feed shows an error or no posts even on a regular page, see our guide on what to check when your feed doesn’t show posts.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about AJAX and your Facebook feed.

Can I use the AJAX theme loading fix in the free version?

Yes. The free version has the same AJAX theme loading fix box on the Advanced tab of Facebook Feed » Settings. Facebook Feed Pro has it too.

Can I turn the fix on for one feed only?

Yes. Add ajax=true to that feed’s shortcode, for example [custom-facebook-feed feed=1 ajax=true]. To turn the fix off for one feed while the setting is on, add ajax=false. Our shortcode reference lists the ajax option too.

Do I need both fixes?

Not always. Turn on the setting first and check your feed. Add cff_init(); only if the feed still doesn’t load properly.

support

Couldn’t find your answer in the docs?

Contact Support