[英]Style.css not overwriting parent style.css although style.css and functions.php are set up
I have been trying to fix this for two days, looking at the different answers on here.我已经尝试解决这个问题两天了,在这里查看不同的答案。
Whenever I edit css in the 'Additional CSS' editor in WP, I get the desired results.每当我在 WP 的“附加 CSS”编辑器中编辑 css 时,我都会得到想要的结果。 However, I can't seem to do this from the style.css sheet.但是,我似乎无法从 style.css 表中执行此操作。 Not that I need to do it from there, but it indicates to me that my child theme is not set up properly.并不是说我需要从那里开始,但它向我表明我的子主题设置不正确。
My style.css file:我的 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
*/
my functions.php:我的功能。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' );
}
?>
any idea what is wrong within these two?知道这两个有什么问题吗?
Thanks谢谢
You are only loading the parent-style in your functions.php.您只在您的函数中加载父样式。php。 So you do not load the style.css of your child theme.所以你不要加载你的子主题的 style.css。 To make it work, you will have enqueue your child theme's stylesheet as well:为了使其工作,您还将将您的子主题的样式表排入队列:
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' );
For the template directory uri (parent theme)对于模板目录 uri(父主题)
get_template_directory_uri()
For the child theme directory uri对于子主题目录uri
get_stylesheet_directory_uri()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.