WordPress子主题:如何覆盖子目录中存在的父主题.css文件?

时间:2020-04-15 15:22:41

标签: wordpress wordpress-theming child-theming

我的子主题中有一个/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.

1 个答案:

答案 0 :(得分:0)

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

parent-theme/inc/theme_styles.php

child-theme/inc/theme_styles.php

并在同一文件内,但在子主题下替换

get_template_directory_uri()

get_theme_file_uri()

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

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

相关问题