php - WordPress child 主题 : How do I add a custom style sheet from my parent theme to my child theme?

标签 php css wordpress wordpress-theming

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

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

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

最佳答案

目前推荐的排队父主题样式表的方法是添加一个wp_enqueue_scripts作用与使用wp_enqueue_style()在您 child 的主题中 functions.php .

加载您的 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 相同。检查您的父主题以查找处理程序

关于php - WordPress child 主题 : How do I add a custom style sheet from my parent theme to my child theme?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43792098/

相关文章:

Php Mysql Ajax 无限滚动

php - 不明白为什么 if 语句没有 {}

javascript - 当我使用下拉菜单时查询整个月份,它会调用/显示数据库中的值

jquery - 在我的情况下如何使相对 div 居中?

容器内的 HTML 3 div,只有中间的 div 具有无限滚动

php - 使用 php 文件连接 wordpress 上的表单页面

php - 如何通过 PHP 上传视频,并通过 FFmpeg 进行转码

javascript - 本地 anchor 链接在 chrome 桌面浏览器中不起作用

WordPress的永久链接不停留

php - 使用另一个标签将缩略图添加到 WordPress RSS