首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress twenty20主题子css无效

WordPress twenty20主题子css无效
EN

Stack Overflow用户
提问于 2020-02-17 00:55:29
回答 1查看 430关注 0票数 0

我按照所有的说明创建了我的子主题。在functions.php中,我有:

代码语言:javascript
复制
<?php

    add_action( 'wp_enqueue_scripts', 'tt_child_enqueue_parent_styles' );

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

?>

在style.css中,我有正确的标题注释部分:

代码语言:javascript
复制
/*
 Theme Name:   Twenty Twenty Child
 Theme URI:    http://example.com/twenty-twenty-child/
 Description:  Twenty Twenty Child Theme
 Author:       X Y
 Author URI:   http://example.com
 Template:     twentytwenty
 Version:      1.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:  twentytwentychild
*/

h1 {
    visibility: hidden;
}

但是,似乎孩子的style.css不工作,没有效果。在页面HTML代码中,下面的几行代码显示正确:

代码语言:javascript
复制
<link rel='stylesheet' id='parent-style-css'  href='https://lifepromise.co.uk/wp-content/themes/twentytwenty/style.css' media='all' />
<link rel='stylesheet' id='twentytwenty-style-css'  href='https://lifepromise.co.uk/wp-content/themes/twentytwenty-child/style.css' media='all' />
EN

回答 1

Stack Overflow用户

发布于 2020-02-17 02:30:00

在function.php上尝试此代码

代码语言:javascript
复制
add_action( 'wp_enqueue_scripts', 'tt_child_enqueue_parent_styles' );

function tt_child_enqueue_parent_styles() {
   wp_enqueue_style( 'twentytwenty-style', get_template_directory_uri().'/style.css' );
   wp_enqueue_style( 'child-style', get_stylesheet_directory_uri().'/style.css', array('twentytwenty-style') );
}

经过测试并正常工作

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

https://stackoverflow.com/questions/60250866

复制
相关文章

相似问题

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