全局注册样式,但有选择地将其排队

时间:2013-04-01 作者:Syed

我试图在插件中获得我的主题注册样式表,目的是我想在插件中获得所有样式表,然后操纵那些注册的样式。

通过注册的样式表

add_action(\'wp_enqueue_scripts\', \'mytheme_register_styles\', 1);

add_action(\'wp_enqueue_scripts\', \'mytheme_enqueue_styles\', 5);
正如您所知,此操作不会在后端触发,因此我需要一种可挂起/可调用的方式,以便它进入队列,我可以根据需要修改/操作并重新保存它们。

1 个回复
SO网友:Pat J

如果希望在后端注册样式表,请使用admin_enqueue_scripts 行动

function wp94156_register_styles() {
    wp_register_style(
        \'your-stylesheet\',
        get_stylesheet_directory_uri() . \'/your-stylesheet.css\',
        $deps, // optional
        $version // optional
    );
    // since you only want it registered, we won\'t enqueue it
}
add_action( \'admin_enqueue_scripts\', \'wp94156_register_styles\' );

结束