在一个插件中注册脚本,并在另一个插件中将其排队

时间:2015-08-21 作者:Nathan Powell

我需要在一个插件中注册一个脚本,然后将其放入另一个插件中。这不是我所期望的那样。我错过什么了吗?

注册脚本的插件:

add_action( \'wp_enqueue_scripts\', \'my_register_styles\' );

function my_register_styles() {
        wp_register_style( \'fontawesome\', \'//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css\' );
        //wp_enqueue_style( \'fontawesome\' ); // This works when uncommented.
}
排队脚本的其他插件:

add_action( \'wp_enqueue_scripts\', \'other_register_styles\' );

function my_register_styles() {
       wp_register_style( \'style\', PATH . \'assets/css/style.min.css\' );
       wp_enqueue_style( \'style\' ); // Working as expected

       wp_enqueue_style( \'fontawesome\' ); // Currently not working!
}

1 个回复
最合适的回答,由SO网友:passatgt 整理而成

确定操作的优先级,以便首先运行register\\u样式的函数。(请注意add\\u action函数中的第三个参数)

add_action( \'wp_enqueue_scripts\', \'other_register_styles\', 11 );
function other_register_styles() {
       wp_register_style( \'style\', PATH . \'assets/css/style.min.css\' );
       wp_enqueue_style( \'style\' ); // Working as expected

       wp_enqueue_style( \'fontawesome\' ); // Currently not working!
}
默认优先级为10,因此只需将11添加到其他\\u register\\u样式。

结束

相关推荐

排除Plugins.php HTTP安装路径与单个插件的HTTPS的故障

我正在尝试对插件中显示的安装路径进行故障排除。php作为我在自己的网站上安装的插件,我最初并没有编写该插件。当我的站点的其余部分是HTTPS时,此插件引用和安装的所有资源都会显示为混合内容HTTP。我一直在玩弄下面的代码段,但它似乎没有起到什么作用,也没有解决问题。有人能指出我遗漏了什么吗? /** * registers scripts and stylesheets */ public function register_assets() {&