I'm building a theme. The theme post navigation is done through jQuery Ajax. I've been several plugins to see compatibility and I have a problem with the Ajax functionallity.

Some plugins such as Jetpack, load certain scripts depending on the post content.Say for example Page1 has no post with VideoPress functionallity and Page2 does. Then scripts necessary will be loaded on Page2 only. I get into a problem as the user might go to Page1, then Page2 posts will load through Ajax and the Video post (from Page2) will break as the scripts were not loaded at first on Page 1.

Is there a way to solve this? I'm quite lost on how to.

1 Answer 1


If the plugins are nice about it and register all of their scripts upfront, and then just enqueue them as needed, you should be able to enqueue all of them to load all the time. Find out the handles they were registered with and enqueue them.

add_action('wp_enqueue_script', function() {
}, 20);

However, some plugins register scripts through the wp_enqueue_script() function even when they conditionally load them. For those, you will need to copy those enqueue statements and modify the paths to the scripts so that they'll load correctly.

add_action('wp_enqueue_script', function() {
    $url = plugins_url('js/example.js', 'example-plugin/x');
    wp_enqueue_script('example-handle', $url /* and any other params they had */);
}, 20);
  • But this means I have to check manually for the enqueue right?
    – Alvaro
    Commented Dec 1, 2013 at 14:56
  • You'll need to search the code of your plugins to find the scripts and stylesheets they enqueue, then enqueue them all in anticipation that they'll be needed.
    – webaware
    Commented Dec 1, 2013 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.