我的父主题有一个样式表: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/