📄 原始资料 | 展开查看原始 JSON(bricks-theme_styles.json){ “name”: “bricks/theme_styles”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-theme_styles/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/theme_styles”, “description”: { “en”: “Filters the arr…
📄 原始资料 | 展开查看原始 JSON(bricks-theme_styles.json)
{
"name": "bricks/theme_styles",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-theme_styles/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/theme_styles",
"description": {
"en": "Filters the array of Theme Styles loaded from the database. This allows you to modify, add, or remove Theme Styles programmatically.",
"zh": "筛选从数据库加载的主题样式数组。允许你以编程方式修改、添加或删除主题样式。"
},
"parameters": [
{
"name": "styles",
"type": "array",
"type_zh": null,
"description": {
"en": "Associative array of Theme Styles, where the key is the style name and the value is an array of style data.",
"zh": "主题样式的关联数组,键为样式名称,值为样式数据数组。"
}
}
],
"example_usage": "add_filter( 'bricks/theme_styles', function( $styles ) {\n // Example: Add a default property to all theme styles\n foreach ( $styles as $key => $style ) {\n if ( ! isset( $styles[ $key ]['settings']['typography'] ) ) {\n $styles[ $key ]['settings']['typography'] = [ 'font-size' => '16px' ];\n }\n }\n\n\n return $styles;\n} );"
}
前言
筛选从数据库加载的主题样式数组。允许你以编程方式修改、添加或删除主题样式。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/theme_styles', function( $styles ) {
// Example: Add a default property to all theme styles
foreach ( $styles as $key => $style ) {
if ( ! isset( $styles[ $key ]['settings']['typography'] ) ) {
$styles[ $key ]['settings']['typography'] = [ 'font-size' => '16px' ];
}
}
return $styles;
} );
参数
$styles (array):主题样式的关联数组,键为样式名称,值为样式数据数组。
示例代码
筛选返回值
add_filter( 'bricks/theme_styles', function( $styles ) {
// Example: Add a default property to all theme styles
foreach ( $styles as $key => $style ) {
if ( ! isset( $styles[ $key ]['settings']['typography'] ) ) {
$styles[ $key ]['settings']['typography'] = [ 'font-size' => '16px' ];
}
}
return $styles;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/theme_styles', function( $value, $styles ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。