5

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!

9

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' ) 
);
  • 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

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.