【问题标题】:WordPress Child Theme: How do I add a custom style sheet from my parent theme to my child theme?WordPress 子主题:如何将自定义样式表从父主题添加到子主题?
【发布时间】:2017-05-05 05:00:20
【问题描述】:

我的父主题有一个样式表:app/assets/css/screen.css,由于某种原因,它包含了所有主题的样式,而不是在 /style.css 中

由于我正在自定义主题,因此我设置了一个子主题,但是我添加到子主题的 style.css 中的更改不起作用。

如何将 app/assets/css/screen.css 样式表添加到我的子主题中,以便进行必要的修改?

【问题讨论】:

  • 可能是您的子主题 style.css 文件在 app/assets/css/screen.css 之前加载 - 在 Wordpress Stack Exchange 中发布您的 WordPress 相关问题

标签: php css wordpress wordpress-theming


【解决方案1】:

目前将父主题样式表加入队列的推荐方法是添加一个wp_enqueue_scripts 操作并在您的子主题的functions.php 中使用wp_enqueue_style()

使用适当的处理程序加载您的 style.css 文件,正如您所说的,您有多个 style.css 文件,您必须确保维护所有父主题依赖项。

if ( ! function_exists( 'prefix_theme_enqueue_scripts' ) ) {
    function prefix_theme_enqueue_scripts() {
        wp_enqueue_style( 'parent_handler', get_template_directory_uri() . '/app/assets/css/screen.css' );
        wp_enqueue_style( 'child_handler',
            get_stylesheet_directory_uri() . '/style.css',
            array('parent_handler')
        );
    add_action( 'wp_enqueue_scripts','prefix_theme_enqueue_scripts' );
    }
}

parent_handler 与父主题注册样式表时使用的 $handle 相同。检查处理程序的父主题

【讨论】:

    猜你喜欢
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多