首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的wordpress子主题没有应用css更改

我的wordpress子主题没有应用css更改
EN

Stack Overflow用户
提问于 2020-05-29 20:53:29
回答 1查看 151关注 0票数 0

我从夜莺主题中创建了一个子主题,但是当我试图在nigthingale- child /style.css中更改propetry时,它就不适用了。例如,我试图更改主体的背景色,或者不为h1标记显示任何颜色,只是为了查看我的子主题style.css是否工作,但什么也没有发生。

我遵循了创建子主题的所有步骤:-new文件夹,夜莺-子-inside,我添加了两个文件: function.php & style.css,这里是my style.css:

代码语言:javascript
复制
/*
 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:

代码语言:javascript
复制
<?php 
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

function enqueue_parent_styles() {
   wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

有人知道我的夜莺儿童主题有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-29 21:18:05

您的函数正在加载父主题CSS。您需要更改一些东西来加载子CSS:

代码语言:javascript
复制
<?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' );
}

在这个实例中,您希望使用get_stylesheet_directory_uri(),因为get_template_directory_uri()总是指向父主题,在父主题中,get_stylesheet_directory_uri()指向子主题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62094446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档