wp_enqueue_classic_theme_styles()
云策文档标注
概述
wp_enqueue_classic_theme_styles() 函数用于在前端为经典主题加载样式,主要用于 Button 和 File 块的向后兼容性。
关键要点
- 该函数检查主题或其父主题是否没有 theme.json 文件,若无则加载 'classic-theme-styles' 样式表。
- 主要用于支持 Button 和 File 块在经典主题中的样式兼容。
- 自 WordPress 6.1.0 引入,后续版本有更新,如 6.8.0 将样式表注册移出此函数。
代码示例
function wp_enqueue_classic_theme_styles() {
if ( ! wp_theme_has_theme_json() ) {
wp_enqueue_style( 'classic-theme-styles' );
}
}注意事项
- 此函数依赖于 wp_theme_has_theme_json() 来检测主题配置,确保在无 theme.json 时才加载样式。
- 相关函数包括 wp_theme_has_theme_json() 和 wp_enqueue_style(),用于检查和加载样式。
原文内容
Loads classic theme styles on classic themes in the frontend.
Description
This is used for backwards compatibility for Button and File blocks specifically.
Source
function wp_enqueue_classic_theme_styles() {
if ( ! wp_theme_has_theme_json() ) {
wp_enqueue_style( 'classic-theme-styles' );
}
}