【发布时间】:2020-09-13 20:32:48
【问题描述】:
我正在尝试创建一个子主题,functions.php 似乎可以正常工作,但由于某种原因,子主题没有加载。我在我的functions.php中添加了以下内容,它确实有效,只是它加载了父主题的style.css而不是子主题。
add_action( 'wp_enqueue_scripts', function() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
});
这是我在孩子中的 style.css 的顶部:
/*
Theme Name: Chaplin Child
Theme URI: https://my-site.com/
description: Child Theme
Template: Chaplin
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: stack-child
*/
【问题讨论】:
-
您的代码告诉 WordPress 仅加载父主题的样式表,仅此而已。这就是为什么它不从您的子主题加载样式表的原因。 documentation 有关于如何加载两个样式表的示例,你试过了吗?
-
是的,我做到了。 functions.php 代码的第一个版本没有改变任何东西。第二次添加了表单,但是父样式表中的任何样式都会覆盖子样式表中的 CSS。
-
那么问题是您如何为您的子主题编写 CSS 规则。这是一本好书:CSS Specificity.
标签: css wordpress wordpress-theming