Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
share|improve this question
    
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
add comment

1 Answer 1

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);
share|improve this answer
    
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
add comment

Your Answer

 
discard

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.