Make jQuery library load before plugin files

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!

1
1

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

Leave a Comment