WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my functions.php, I have set a register_scripts() and load_scripts(), and hooked them to the 'init' action.

I have registered all the scripts to be loaded in the footer, in order to optimize page load.

Some of the scripts I've registered in register_scripts() are not enqueued in load_scripts() because I only want to load them when / if they are needed.

So for example, if the page being rendered includes the template part 'gallery.php', which needs 'jquery-gallery', I would like to enqueue it from that file, but only after the rest of the footer scripts have been loaded. I also need to do this with inline scripts.

Hope I explained myself well... If not please ask.

share|improve this question

If you enqueue the script to the footer while the page is being rendered (after the "wp_head" hook), you will have to manually add wp_print_scripts (or wp_print_footer_scripts) to the wp_footer action, like this:

wp_enqueue_script( 'jquery-gallery', null, array( 'jquery' ), null, true );
add_action( 'wp_footer', create_function( '', 'wp_print_scripts( "jquery-gallery" );' ) );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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