WordPress的子主题不会覆盖父主题的CSS

时间:2018-09-25 00:34:26

标签: php html css wordpress

我正在尝试为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' );
 }
?>

为了测试新的子主题,我在子样式中添加了以下代码。css

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

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

对于我在做错事情的任何帮助,我们深表感谢。

2 个答案:

答案 0 :(得分: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' ) );
}

答案 1 :(得分:0)

感谢所有建议。

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

相关问题