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 am using a few jQuery plugins such as validate.js, but they all load BEFORE the Jquery library which is loaded automatically by WordPress and my theme.

I need the plugins to load after - so is there a way to make Jquery load first in functions.php - so that I can use it frontend and admin.

I am currently loading the following in functions.php

wp_enqueue_script('validation',
get_bloginfo('template_url') ."/js/jquery.validate.min.js");

wp_enqueue_script('scripts',
get_bloginfo('template_url') ."/js/scripts.js");

Any help, massively appreciated!

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

If you look at the wp_enqueue_script Codex Documentation, you'll see one of the options is $deps, this would mean that your script is dependent upon another script, simply add jquery as a dependancy and your scripts will load in the correct place.

If you set a handle for the other scripts you can use them as a dependent as well.

Example:

wp_enqueue_script( 
    'your-handle', 
    get_bloginfo('template_url') . '/path/script.js', 
    array( 'jquery' ) 
);
share|improve this answer
    
Cheers JK - seemed to get it working by simply ordering it in functions.php - yet when I tried it the first time it didn't work. Using dependencies is definitely the way to go! –  Adam Moss Nov 29 '11 at 14:58
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.