wordpress - 我的 wordpress 子主题不应用 css 更改
问题描述
我从 nightingale 主题创建了一个子主题,但是当我尝试更改 nigthingale-child/style.css 中的属性时,它不适用。例如,我尝试更改正文的背景颜色或为 h1 标记不显示任何内容,以查看我的子主题 style.css 是否有效,但没有任何反应。
我已经按照创建子主题的所有步骤进行操作:-new 文件夹 nightingale-child -在这个 foder 中我添加了两个文件:function.php 和 style.css 这是我的 style.css:
/*
Theme Name: nightingale-child
Theme URI: http://example.com/twenty-fifteen-child/
Description: nightingale Child Theme
Author: John Doe
Author URI: http://example.com
Template: nightingale
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: nightingalechild
*/
a {
color: red;
}
这是我的function.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' );
}
有人知道我的夜莺儿童主题有什么问题吗?
解决方案
您的函数正在加载 PARENT 主题 CSS。您需要更改一些内容来加载 CHILD CSS:
<?php
// Let's change this to `enqueue_child_styles` so it's clearer.
add_action( 'wp_enqueue_scripts', 'enqueue_child_styles' );
// Now the function
function enqueue_child_styles() {
// Rename the hook to child-style
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri().'/style.css' );
}
在这种情况下,您要使用as 始终指向 PARENT 主题,而 asget_stylesheet_directory_uri()
指向CHILD 主题。get_template_directory_uri()
get_stylesheet_directory_uri()
推荐阅读
- unit-testing - NUnit with .NetCore - 我可以将测试结果写入 xml 或 trx 文件吗
- angular - 尝试实施本地存储时我的网站无法加载
- asp.net-mvc - 如何在剃刀视图中访问会话对象属性?
- spring-boot - 在 Spring Boot 应用程序中使用来自 Confluent 的 Schema Registry 与 Avro 和 Kafka
- java - Java从字符串中删除公钥页眉和页脚
- java - 是否有检查输出的多个变量的操作?
- php - 如何在 HTML 隐藏字段中使用 GET 变量作为值?
- php - 从 laravel 刀片上的循环访问数据
- python - 与熊猫数据框列比较后,在 .csv 文件中添加行
- c# - 禁用在 HttpWebRequests 之间重用 ServicePoint