javascript - wrong enqueue script order in wordpress child theme - Stack Overflow

I'm trying to enqueue my script in a child theme in wordpress, but i get it loaded before Jquery e

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
Add a ment  | 

2 Answers 2

Reset to default 6

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

In addition to @sirBlond,
In my case the hook = '' did not work.

I changed it to:

function print_filters_for($hook)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744351144a4569982.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信