最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Enqueue script globally

programmeradmin2浏览0评论

This only works for admin dashboard.

add_action('admin_enqueue_scripts',array($this, 'login_register96_adminscripts'));

And this only works for the user place.

add_action( 'wp_enqueue_scripts', array($this , 'login_register96_scripts') );

Is there a way I can enqueue a script globally? Which will be operational on the whole website including admin dashboard.

This only works for admin dashboard.

add_action('admin_enqueue_scripts',array($this, 'login_register96_adminscripts'));

And this only works for the user place.

add_action( 'wp_enqueue_scripts', array($this , 'login_register96_scripts') );

Is there a way I can enqueue a script globally? Which will be operational on the whole website including admin dashboard.

Share Improve this question asked Aug 5, 2020 at 21:37 Saqib AliSaqib Ali 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

I'm not aware of any other way but to use both add_action lines, for a single function.

Example:

function my_enqueue_sripts_function_name(){
    
    // your enqueue logic here
    
}
add_action('wp_enqueue_scripts',    'my_enqueue_sripts_function_name' );
add_action('admin_enqueue_scripts', 'my_enqueue_sripts_function_name' );

There's no rule that forbids you from adding the same function on multiple hooks.

Furthermore, if you need to know which action called the function, from within the function, you can use current_action() or current_filter()

发布评论

评论列表(0)

  1. 暂无评论