I’m trying to enqueue my script in a child theme in wordpress, but i get it loaded before Jquery even though I’ve specified Jquery dependency.
The code:
add_action( 'wp_enqueue_scripts', 'child_theme_scripts' );
function child_theme_scripts(){
wp_enqueue_script( 'dynamic-menu-script', get_stylesheet_directory_uri() . '/js/dynamic-menu.js', array( 'jquery' ) );
}
no matter what I do (I tried registering first, then specifying my script in the array after jquery, i tried to specify to load the script in the footer, i tried to enqueue JQuery externally) my script loads before query throwing me a “ReferenceError: Can’t find variable: JQuery” I’ve checked JQ is loading properly but after my script.
this thing is driving me crazy, please help me…
You can improve the order of scripts loading with priority parameter. Default priority is 10, so you may set it to 11.
Here’s a simple helper function that shows you what functions are assigned to the hook you want to use.
you can call it anywhere in templates with
print_filters_for( 'wp_enqueue_scripts' );
In addition to @sirBlond,
In my case the
hook = ''
did not work.I changed it to: