【问题标题】:My wordpress child-theme doesn't apply css changes我的 wordpress 子主题不应用 css 更改
【发布时间】:2020-05-30 05:18:05
【问题描述】:

我从 nightingale 主题创建了一个子主题,但是当我尝试更改 nigthingale-child/style.css 中的属性时,它不适用。例如,我尝试更改正文的背景颜色或为 h1 标记不显示任何内容,只是为了查看我的子主题 style.css 是否有效,但没有任何反应。

我已按照创建子主题的所有步骤操作: - 新文件夹 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' );
}

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

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您的函数正在加载 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' );
    }
    

    在这种情况下,您想使用 get_stylesheet_directory_uri(),因为 get_template_directory_uri() 始终指向 PARENT 主题,而 get_stylesheet_directory_uri() 指向 CHILD 主题。

    【讨论】:

    • 非常感谢您的帮助。我还错误地命名了我的 function.php 文件:它是函数而不是函数。否则 wordpress 无法识别该文件。
    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    相关资源
    最近更新 更多