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

I am loading scripts like this:

//load scripts
//wp_register_script( $handle, $src, $deps, $ver, $in_footer );

add_action('wp_enqueue_scripts', 'load_scripts');

function load_scripts() {

    if (!is_admin()) {

        wp_register_script('modernizr', get_bloginfo('template_directory') .'/scripts/modernizr-latest.js',false);

        wp_enqueue_script('jquery', true );

        wp_register_script('cookie',get_bloginfo('template_directory') . '/scripts/cookie.js', array('jquery'), '1.0',true);

        wp_register_script( 'Gmaps', 'http://maps.google.com/maps/api/js?sensor=false', true );
        wp_enqueue_script ('Gmaps');

        wp_register_script('plugins', get_bloginfo('template_directory') .'/scripts/plugins.js',true);

        wp_register_script( 'maps_scripts',  get_bloginfo('template_directory') . '/scripts/maps.js', array('Gmaps'), '1.0', true );
        wp_enqueue_script ('maps_scripts');

        wp_register_script('history', get_bloginfo('template_directory') .'/scripts/history.js', array('jquery'), '1.0',true);


With this I expect to see all scripts except modernizr loaded into the footer. Instead it is an incorrect mish-mash. From this example jquery, google maps, and the plugins.js still load in the header even though $in_footer is set to true. Cookie, maps, and history load in the footer as expected.

Can someone please help explain this to me?

share|improve this question
up vote 2 down vote accepted

Just a note before I get into the solution, get_template_directory_uri() is preferred to get_bloginfo() because it is a filtered output. That said, in the corrected code I have left it the way you had it, to save you typing in the case that you had a reason for leaving it that way.

Your issue is that you're neglecting some parameters, the parameter before the parenthesis is not the last parameter, it always counts from the left, so in a lot of these, you have set $ver to true rather than the $in_footer to true. Also, you should not need to enqueue jquery, that should be done automatically, but there's no harm in doing it anyways.

add_action( 'wp_enqueue_scripts', 'load_scripts ');

function load_scripts() {

    if ( !is_admin() ) {

        wp_enqueue_script( 'jquery' );

        wp_register_script( 'modernizr', get_bloginfo( 'template_directory' ) .'/scripts/modernizr-latest.js' );
        wp_enqueue_script( 'modernizr' );

        wp_register_script( 'cookie', get_bloginfo( 'template_directory' ) . '/scripts/cookie.js', array( 'jquery' ), '1.0', true );
        wp_enqueue_script( 'cookie' );

        wp_register_script( 'Gmaps', 'http://maps.google.com/maps/api/js?sensor=false', array(), false, true );
        wp_enqueue_script ( 'Gmaps' );

        wp_register_script( 'plugins', get_bloginfo( 'template_directory' ) .'/scripts/plugins.js', array(), false, true );
        wp_enqueue_script( 'plugins' );

        wp_register_script( 'maps_scripts',  get_bloginfo( 'template_directory' ) . '/scripts/maps.js', array( 'Gmaps' ), '1.0', true );
        wp_enqueue_script ( 'maps_scripts' );

        wp_register_script( 'history', get_bloginfo( 'template_directory' ) .'/scripts/history.js', array( 'jquery' ), '1.0', true );
        wp_enqueue_script( 'history' );


Just a note: this might be worth a read, it helps to get everything uniform. Personally I try to write everything to the coding standard, even if it doesn't have to be, as a habit of good practice.

share|improve this answer
Thanks! I really appreciate the extra links and information too. I am on a mission to clean up code now =) – zac Jan 9 '12 at 16:22

I've always found http://scribu.net/wordpress/optimal-script-loading.html a good resource for some interesting loading practices to improve performance. Cheers.

share|improve this answer
Answers must be independent of other sites so please add an enough description here because links may be broken in the future so . – Mouneer Nov 28 '15 at 10:57

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.