神秘的 Divi 儿童主题 css 被忽略
Mysterious Divi child theme css being ignored
这让我发疯。
子主题 .css 已加载,在父样式之后,但 CSS 未应用/未覆盖,我四处搜索并看到其他几个人抱怨关于这个。
排队样式甚至为其添加优先级都不能解决问题。
通过主题定制器添加相同的 CSS,实际上应用了 CSS,因此 CSS 本身不是这里的问题。
我还能做些什么?!
我终于找到了解决问题的enque设置,
function my_theme_enqueue_styles() {
wp_register_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array(),
filemtime( get_stylesheet_directory() . '/style.css' )
);
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
显然对我有影响的是函数属性中的“array('parent-style')”值,必须进一步调查它,但这是唯一解决它的方法。
您是否在 wp_enqueue_script()
中添加了依赖项?
/**
* Proper way to enqueue scripts and styles
Example...
*/
function wpdocs_theme_name_scripts() {
wp_enqueue_style(
'stylesheet-name', // it will append '-css' in your source
get_template_directory_uri() . '/css/stylesheet-name.css',
array('parent-style'), // dependants (reliable on other stylesheet)
'null', // version, null or version number (1.0.1 etc)
'all' // media
);
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
注意:如果您的队列中有版本号,那么缓存可能会阻止它加载。有的人用date()
每次刷新都改值...
这让我发疯。
子主题 .css 已加载,在父样式之后,但 CSS 未应用/未覆盖,我四处搜索并看到其他几个人抱怨关于这个。
排队样式甚至为其添加优先级都不能解决问题。
通过主题定制器添加相同的 CSS,实际上应用了 CSS,因此 CSS 本身不是这里的问题。
我还能做些什么?!
我终于找到了解决问题的enque设置,
function my_theme_enqueue_styles() {
wp_register_style(
'child-style',
get_stylesheet_directory_uri() . '/style.css',
array(),
filemtime( get_stylesheet_directory() . '/style.css' )
);
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
显然对我有影响的是函数属性中的“array('parent-style')”值,必须进一步调查它,但这是唯一解决它的方法。
您是否在 wp_enqueue_script()
中添加了依赖项?
/**
* Proper way to enqueue scripts and styles
Example...
*/
function wpdocs_theme_name_scripts() {
wp_enqueue_style(
'stylesheet-name', // it will append '-css' in your source
get_template_directory_uri() . '/css/stylesheet-name.css',
array('parent-style'), // dependants (reliable on other stylesheet)
'null', // version, null or version number (1.0.1 etc)
'all' // media
);
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
注意:如果您的队列中有版本号,那么缓存可能会阻止它加载。有的人用date()
每次刷新都改值...