Force Enqueued Scripts to Load After jQuery

I’ve been running into “Uncaught referenceError: jQuery is not defined” a lot lately when working with scripts and plugins that I’ve used for years. It’s unbelievably annoying to have something that’s worked one way for most of my career to suddenly stop working and bring up errors.

Nonetheless, I’ve found a solution!

function theme_scripts() {        
        // slick slider
	wp_register_script('slick',get_bloginfo('stylesheet_directory').'/js/slick/slick.min.js', array( 'jquery' ));
add_action( 'wp_enqueue_scripts', 'theme_scripts' );

Add array(‘jquery’) to enqueued scripts to tell the function that the script relies on jQuery and to load it after jquery.js in your WordPress install.

Sourced here.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.

%d bloggers like this: