开发者

Wordpress add_action of wp_head for javascript / css files in plugin

开发者 https://www.devze.com 2022-12-27 23:21 出处:网络
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.

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 qu开发者_运维知识库estion - what's the appropriate way to make the script wait for jquery to load first?


If 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消