php - 如何让我的子主题的样式表在父主题的 'Colour Theme' 样式表之后加载?

标签 php css wordpress

我已经创建了一个子主题,我已经按如下方式将样式表排入队列:

<?php
function child_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'custom_css', get_template_directory_uri() . '/css/custom-stylesheet.css', array(), '1.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles', 10 );
?>

以上代码确保子主题自定义样式表在父主题样式表之后加载。也就是说,父主题在以下目录中还有以下 CSS 文件,它们在子主题样式表之后加载:

<link rel='stylesheet' id='responsive-css'  href='http://www.example.com/wp-content/themes/theme/assets/css/responsive.css?ver=4.7.3' type='text/css' media='all' />
<link rel='stylesheet' id='theme-skin-color8-css'  href='http://www.example.com/wp-content/themes/theme/assets/css/theme-skin/color8.css?ver=4.7.3' 

我已经检查了上述文件的优先级设置,但均未设置。我还更改了子主题样式表的优先级,但这没有任何影响。

有没有人有任何其他可能的建议,我可以尝试,以确保子主题样式表加载最后?

最佳答案

如果调用其他样式表的 wp_enqueue_scripts 函数没有设置优先级,那么它们的优先级为 10,将您的调用设置为更高的优先级将起作用:

function child_theme_enqueue_styles() {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'custom_css', get_template_directory_uri() . '/css/custom-stylesheet.css', array(), '1.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles', 11 );

如果这不起作用,则说明父主题编码不当并且没有正确排队其他样式表。

关于php - 如何让我的子主题的样式表在父主题的 'Colour Theme' 样式表之后加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43151801/

相关文章:

php - wpdb::prepare() 缺少参数 2

php - 将 date.timezone 设置为 "date.timezone => no value => no value"后获取 "Europe/Paris"

html - 将可变数量的 div float 到左/右列中

php - Wordpress:带过滤器的存档页面不起作用 (ACF)

php - 显示最新帖子标题的标题标签

php - 同时向父子表插入数据

php - Yii - 通过 CDbCriteria 检索前 10 名

HTML/CSS - 位置 :fixed prevents scroll bar from appearing on minimised screen

python - Django 内容管理系统 : How to modify style of show_menu

css - wordpress:如何更改 wordpress 主题中的内联样式