Bricks 中文文档:bricks/theme_styles/controls

标签TAGS: 

📄 原始资料  |  展开查看原始 JSON(bricks-theme_styles-controls.json){ “name”: “bricks/theme_styles/controls”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-theme_styles-controls/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/theme_styles/controls”, “de…

📄 原始资料  |  展开查看原始 JSON(bricks-theme_styles-controls.json)
{
  "name": "bricks/theme_styles/controls",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-theme_styles-controls/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/theme_styles/controls",
  "description": {
    "en": "Filters the individual controls available within the Theme Styles settings. This allows you to add custom fields to existing Theme Style groups or to your own custom groups.",
    "zh": "筛选主题样式设置中可用的各个控件。允许你向现有主题样式组或你自己的自定义组添加自定义字段。"
  },
  "parameters": [
    {
      "name": "controls",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Associative array of controls.",
        "zh": "控件的关联数组。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/theme_styles/controls', function( $controls ) {\n    // Add a custom color control to the 'colors' group\n    $controls['myCustomColor'] = [\n        'group' => 'colors', // Target existing group\n        'label' => esc_html__( 'My Custom Color', 'my-plugin' ),\n        'type'  => 'color',\n    ];\n\n\n    return $controls;\n} );"
}

前言

筛选主题样式设置中可用的各个控件。允许你向现有主题样式组或你自己的自定义组添加自定义字段。

用法

将代码加入子主题的 functions.php

add_filter( 'bricks/theme_styles/controls', function( $controls ) {
    // Add a custom color control to the 'colors' group
    $controls['myCustomColor'] = [
        'group' => 'colors', // Target existing group
        'label' => esc_html__( 'My Custom Color', 'my-plugin' ),
        'type'  => 'color',
    ];


    return $controls;
} );

参数

  • $controls (array):控件的关联数组。

示例代码

筛选返回值

add_filter( 'bricks/theme_styles/controls', function( $controls ) {
    // Add a custom color control to the 'colors' group
    $controls['myCustomColor'] = [
        'group' => 'colors', // Target existing group
        'label' => esc_html__( 'My Custom Color', 'my-plugin' ),
        'type'  => 'color',
    ];


    return $controls;
} );

根据条件短路返回原值

根据条件跳过或修改返回值:

add_filter( 'bricks/theme_styles/controls', function( $value, $controls ) {
    if ( is_admin() ) { return $value; }
    // TODO: custom logic here
    return $value;
} );

补充说明

更多细节可参考 官方文档