wp_register_script not loading as expected

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.

Leave a Comment