duanfei1268 2017-04-01 01:27
浏览 27
已采纳

如何在父主题的“颜色主题”样式表后加载我的儿童主题样式表?

I have created a Child Theme, whereby I have enqueued the stylesheets as follows:

<?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 );
?>

The above code, ensures that the Child Theme Custom Stylesheet loads after the Parent Theme Stylesheets. That said, the Parent Theme also has the following CSS Files within the following directories, which load after the Child Theme Stylesheets:

<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' 

I have checked the priority settings for the above files and none have been set. I have also changed the priorities of the Child Theme stylesheets, yet this has no affect.

Does anyone have any other possible suggestions, that I can try, in order to ensure that the Child Theme Stylesheet loads last?

  • 写回答

1条回答 默认 最新

  • dongni8124 2017-04-01 01:55
    关注

    If no priority has been set on the wp_enqueue_scripts function calling those other stylesheets, then their priority is at 10 and setting your call to a higher priority will work:

    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 );
    

    If this isn't working, then the parent theme is poorly coded and not properly enqueuing those other stylesheets.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计