0

我的子主题中有一个 /lib/extends_script/extends-style.min.css 文件,我试图覆盖父主题中的版本。我有以下代码,但它似乎仍在加载 .css 文件的父版本。我究竟做错了什么?

Child theme: functions.php

function PREFIX_remove_scripts() {

    // enqueue parent styles
    wp_enqueue_style('maple', get_template_directory_uri() .'/style.css');

    // enqueue child styles
    wp_enqueue_style('maple-child', get_stylesheet_directory_uri() .'/style.css', array('maple'), 99999);       
    wp_enqueue_style('tn-extends-lib-style', get_stylesheet_directory_uri() .'/lib/extends_script/extends-style.min.css');

}

add_action( 'wp_enqueue_scripts', 'PREFIX_remove_scripts', 20 );

父主题 functions.php 以下列方式将其排入队列:

if ( ! function_exists( 'tn_register_frontend_script' ) ) {
    function tn_register_frontend_script() {
        // load css code
        wp_enqueue_style( 'tn-extends-lib-style', get_template_directory_uri() . '/lib/extends_script/extends-style.min.css', array(), TN_THEME_VERSION, 'all' );
etc.
4

1 回答 1

0

将包含脚本或样式的文件从父主题复制到子主题,并具有相同的文件夹嵌套级别,例如:

parent-theme/inc/theme_styles.php

child-theme/inc/theme_styles.php

并在同一个文件中,但在子主题中替换

get_template_directory_uri()

get_theme_file_uri()

现在 wordpress 首先检查子主题中的样式路径。

与父主题具有相同路径的样式表文件也必须在子主题内

于 2020-08-21T20:20:14.283 回答