【问题标题】:WordPress Child Theme: How to override parent theme .css files that exist in subdirectories?WordPress子主题:如何覆盖子目录中存在的父主题.css文件?
【发布时间】:2020-07-28 15:22:04
【问题描述】:

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

【问题讨论】:

    标签: wordpress wordpress-theming child-theming


    【解决方案1】:

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

    parent-theme/inc/theme_styles.php
    

    child-theme/inc/theme_styles.php
    

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

    get_template_directory_uri()
    

    get_theme_file_uri()
    

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

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

    【讨论】:

      猜你喜欢
      • 2019-02-28
      • 1970-01-01
      • 2013-11-10
      • 2018-04-07
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      相关资源
      最近更新 更多