admin管理员组文章数量:1414613
For some reason, the following is not loading my JS and CSS into wordpress. This code is in an activated plugin, which is otherwise executing. Also, I checked and wp_head
does exist in the theme.
add_action ( 'wp_head', 'lbIncludes');
function lbIncludes() {
wp_enqueue_script('jquery');
wp_register_script('myScript',
WP_PLUGIN_URL . '/myScript/myScript.bundle.js' );
wp_enqueue_script('myScript');
wp_register_style('myStyle', WP_PLUGIN_URL . '/myScript/myScript.css');
wp_enqueue_style('myStyle');
};
Bonus question - what's the appropriate way to make the script wait for jquery to load first?
For some reason, the following is not loading my JS and CSS into wordpress. This code is in an activated plugin, which is otherwise executing. Also, I checked and wp_head
does exist in the theme.
add_action ( 'wp_head', 'lbIncludes');
function lbIncludes() {
wp_enqueue_script('jquery');
wp_register_script('myScript',
WP_PLUGIN_URL . '/myScript/myScript.bundle.js' );
wp_enqueue_script('myScript');
wp_register_style('myStyle', WP_PLUGIN_URL . '/myScript/myScript.css');
wp_enqueue_style('myStyle');
};
Bonus question - what's the appropriate way to make the script wait for jquery to load first?
Share Improve this question edited Mar 15, 2013 at 16:12 its_me 11.4k25 gold badges87 silver badges135 bronze badges asked Apr 22, 2010 at 8:35 MatrymMatrym 17.1k35 gold badges99 silver badges141 bronze badges 2- Sigh. You can't enqueue on wp_head. Rather, you have to do it on an init action, such as: add_action ( 'init', 'lbIncludes'); But I still can't get the css to appear. – Matrym Commented Apr 22, 2010 at 9:04
-
Could it be the
};
in the last line? It should be}
– its_me Commented Mar 15, 2013 at 16:09
2 Answers
Reset to default 2If you want to load jQuery before your scripts do this:
wp_register_script('myScript', WP_PLUGIN_URL . '/myScript/myScript.bundle.js', array('jquery') );
Try hooking to wp_print_styles and wp_print_scripts. To ensure jQuery is loaded first add the $deps parameter when you wp_enqueue_script.
本文标签: Wordpress addaction of wphead for javascriptcss files in pluginStack Overflow
版权声明:本文标题:Wordpress add_action of wp_head for javascriptcss files in plugin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745190556a2646890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论