如何在style.css之前加入样式
1 个回答
- 投票数
-
- 2013-04-17
也将
style.css
入队,并将normalize
设置为依赖项:if ( ! is_admin() ) { // Register early, so no on else can reserve that handle add_action( 'wp_loaded', function() { wp_register_style( 'normalize', // parent theme get_template_directory_uri() . '/css/normalize.css' ); wp_register_style( 'theme_name', // current theme, might be the child theme get_stylesheet_uri(), [ 'normalize' ] ); }); add_action( 'wp_enqueue_scripts', function() { wp_enqueue_style( 'theme_name' ); }); }
当打印
theme_name
时,WordPress将首先自动加载依赖项.Enqueue the
style.css
too, and setnormalize
as dependency:if ( ! is_admin() ) { // Register early, so no on else can reserve that handle add_action( 'wp_loaded', function() { wp_register_style( 'normalize', // parent theme get_template_directory_uri() . '/css/normalize.css' ); wp_register_style( 'theme_name', // current theme, might be the child theme get_stylesheet_uri(), [ 'normalize' ] ); }); add_action( 'wp_enqueue_scripts', function() { wp_enqueue_style( 'theme_name' ); }); }
WordPress will load the dependencies now first automatically when
theme_name
is printed.-
万分感谢!只是一个简单的问题-那么我是否不需要排队规范化样式,或者在将其设置为依赖项时会自动完成吗?Great, thanks! Just a quick question - do I then not need to enqueue the normalize style, or is this done automatically when set as a dependency?
- 1
- 2013-04-17
- vonholmes
-
当作为依赖项调用时自动入队.Automatically enqueued when called as a dependency.
- 0
- 2013-04-17
- RRikesh
-
@vonholmes我已将其添加到我的答案中.@vonholmes I have added that to my answer.
- 0
- 2013-04-17
- fuxia
如何在加载style.css之前使.css文件入队?还是让默认的style.css依赖于另一个.css文件?
我正在尝试加载.css重置,而style.css会覆盖该重置.
这就是我所拥有的:
但是这是在style.css之后加载的.