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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?