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...
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...
Share Improve this question asked Jul 23, 2014 at 9:28 user1218631user1218631 2- Are you sure that jQuery dependency is not being changed to another handle in your parent theme? – Rob Schmuecker Commented Jul 23, 2014 at 9:43
- this is a sample enqueue from parent theme wp_enqueue_script( 'theme-methods', get_template_directory_uri() . '/js/methods.js', array( 'jquery' ), '', true ); – user1218631 Commented Jul 23, 2014 at 9:54
2 Answers
Reset to default 6You can improve the order of scripts loading with priority parameter. Default priority is 10, so you may set it to 11.
add_action( 'wp_enqueue_scripts', 'child_theme_scripts', 11 );
Here's a simple helper function that shows you what functions are assigned to the hook you want to use.
function print_filters_for( $hook = '' ) {
global $wp_filter;
if( empty( $hook ) || !isset( $wp_filter[$hook] ) )
return;
print '<pre>';
print_r( $wp_filter[$hook] );
print '</pre>';
}
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:
function print_filters_for($hook)