0

I have the following in my functions.php and it doesn't seem to load jQuery. If I remove the wp_deregister_script() line it appears to load the wordpress included jQuery and not the one I have manually registered (that I can tell). Anyone have any ideas why this would be happening?

function register_scripts() {

        wp_deregister_script('jquery');

        wp_register_script('jquery', 'http://code.jquery.com/jquery-1.7.min.js', '1.7', 1);
        wp_register_script('modernizr', get_bloginfo('template_directory').'/js/libs/modernizr-2.0.6.min.js', 'jquery');    
        wp_register_script('plugins', get_bloginfo('template_directory').'/js/plugins.js', 'jquery', '', 1);    
        wp_register_script('custom', get_bloginfo('template_directory').'/js/script.js', 'jquery', '', 1);

        wp_enqueue_script('jquery');
        wp_enqueue_script('modernizr');
        wp_enqueue_script('plugins');
        wp_enqueue_script('custom');

    }

    add_action('init', 'register_scripts');
  • It appears to be a load order issue. I think it has been fixed but would be interested if anyone could explain this to me? – Craig Nov 9 '11 at 0:48
2

When setting your dependencies they need to be in an array.

wp_register_script('jquery', 'http://code.jquery.com/jquery-1.7.min.js', '1.7', 1);
wp_register_script('modernizr', get_bloginfo('template_directory').'/js/libs/modernizr-2.0.6.min.js', array('jquery') );    
wp_register_script('plugins', get_bloginfo('template_directory').'/js/plugins.js', array('jquery'), '', 1);    
wp_register_script('custom', get_bloginfo('template_directory').'/js/script.js', array( 'jquery') , '', 1);
  • I don't think they need to be in an array unless you have more than one dependency. – Craig Jul 24 '12 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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