admin管理员组文章数量:1301490
function load_my_script(){
wp_register_script( 'my_script', get_template_directory_uri() . '/js/myscript.js', 'jquery' );
wp_enqueue_script( 'my_script', 'jquery');
}
add_action('wp_enqueue_scripts', 'load_my_script');
myscript.js is loading before jquery, why? And how do I make it load AFTER jquery?
Thanks.
function load_my_script(){
wp_register_script( 'my_script', get_template_directory_uri() . '/js/myscript.js', 'jquery' );
wp_enqueue_script( 'my_script', 'jquery');
}
add_action('wp_enqueue_scripts', 'load_my_script');
myscript.js is loading before jquery, why? And how do I make it load AFTER jquery?
Thanks.
Share Improve this question asked Apr 10, 2012 at 17:22 DaveDave 8104 gold badges9 silver badges21 bronze badges2 Answers
Reset to default 21You have a typo in your code. It should be:
function load_my_script(){
wp_register_script(
'my_script',
get_template_directory_uri() . '/js/myscript.js',
array( 'jquery' )
);
wp_enqueue_script( 'my_script' );
}
add_action('wp_enqueue_scripts', 'load_my_script');
The jQuery dependency needs to be an array()
, not just a string. This will force your script to load after jQuery.
get_template_directory_uri()
does give you the theme directory, but this is not what you want if you are using a Child Theme.
get_stylesheet_directory_uri()
will give your the directory of your "current theme", so in either case, it is safest to use.
本文标签: How do I make script load after jquery
版权声明:本文标题:How do I make script load after jquery? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741672276a2391675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论