【问题标题】:Wordpress child theme does not override parent theme cssWordpress 子主题不会覆盖父主题 css
【发布时间】:2019-02-28 12:53:55
【问题描述】:

我正在尝试为 Wordpress 主题二十七创建一个子主题。

我创建了一个名为二十七子的目录,并在其中创建了一个 functions.php 和 style.css 文件。

我不明白为什么我对子 style.css 所做的任何更改都没有实现。

这是我的孩子 style.css:

/*
Theme Name: Twenty Seventeen Child
Theme URL: http://tylerdevries.com
Description: Twenty Seventeen Child Theme
Author: Tyler DeVries
Author URL: http://tylerdevries.com
Template: twentyseventeen
Version: 1.0.0
Text Domain: twentyseventeen-child
*/

这是我的子functions.php

<?php
 add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
 function my_theme_enqueue_styles() {
     wp_enqueue_style( 'parent-style', get_template_directory_uri() . 
 '/style.css' );
 }
?>

为了测试我的新子主题,我在子 style.css 中包含了以下代码

.site-content-contain {
background-color: #d5ffa0;
position: relative;
}

我还尝试了其他简单的 CSS 自定义 - 完全没有影响。

非常感谢任何有关我做错的帮助。

【问题讨论】:

  • 您没有将子主题的 style.css 排入队列,并将“父样式”设置为依赖项。

标签: php html css wordpress


【解决方案1】:
// Queue parent style followed by child/customized style
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', PHP_INT_MAX);

function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/styles/child-style.css', array( 'parent-style' ) );
}

【讨论】:

    【解决方案2】:

    感谢所有建议。

    原来我的原始代码是正确的。问题与我的浏览器缓存有关。清除缓存后,我的更改可见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 2014-08-17
      • 2018-04-07
      相关资源
      最近更新 更多