wrong enqueue script order in wordpress child theme

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:

Read More
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…

Related posts

Leave a Reply

2 comments

  1. You 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' );