Style.css 尽管设置了 style.css 和 functions.php,但未覆盖父级 style.css

Style.css not overwriting parent style.css although style.css and functions.php are set up

两天来我一直在尝试解决这个问题,看看这里的不同答案。

每当我在 WP 的 'Additional CSS' 编辑器中编辑 css 时,我都会得到想要的结果。但是,我似乎无法从 style.css sheet 执行此操作。并不是说我需要从那里开始,但它向我表明我的子主题设置不正确。

我的style.css文件:

/*
Theme Name: Coblog-child
Template: coblog
Author: [name]
Description: Coblog Child
Version: 1.1.0.1588784301
Updated: 2020-05-06 16:58:21
*/

我的functions.php:

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

知道这两者有什么问题吗?

谢谢

您只是在 functions.php 中加载父级样式。 所以你不加载你的子主题的 style.css 。 为了使其工作,您还需要将子主题的样式表加入队列:

function child_theme_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-theme-css', get_stylesheet_directory_uri() .'/style.css' , array('parent-style'));
}
add_action( 'wp_enqueue_scripts', 'child_theme_styles' );

对于模板目录uri(父主题)

get_template_directory_uri()

为子主题目录uri

get_stylesheet_directory_uri()