📄 原始资料 | 展开查看原始 JSON(bricks-wpml-exclude_controls_from_translation.json){ “name”: “bricks/wpml/exclude_controls_from_translation”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-wpml-exclude_controls_from_translation/”, “scraped_at”: “2026-08-29…
📄 原始资料 | 展开查看原始 JSON(bricks-wpml-exclude_controls_from_translation.json)
{
"name": "bricks/wpml/exclude_controls_from_translation",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-wpml-exclude_controls_from_translation/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/wpml/exclude_controls_from_translation",
"description": {
"en": "Filters Bricks control keys excluded from WPML translation. Return the control keys that should not be translated for the current element/control context.",
"zh": "筛选从 WPML 翻译中排除的 Bricks 控件键。返回在当前元素/控件上下文中不应被翻译的控件键。"
},
"parameters": [
{
"name": "excluded_keys",
"type": "array",
"type_zh": null,
"description": {
"en": "Control keys excluded from translation.",
"zh": "从翻译中排除的控件键。"
}
},
{
"name": "element",
"type": "array",
"type_zh": null,
"description": {
"en": "The Bricks element data.",
"zh": "Bricks 元素数据。"
}
},
{
"name": "control",
"type": "array",
"type_zh": null,
"description": {
"en": "The control definition.",
"zh": "控件定义。"
}
},
{
"name": "key",
"type": "string",
"type_zh": null,
"description": {
"en": "The current control key or repeater field key.",
"zh": "当前的控件键或 repeater 字段键。"
}
}
],
"example_usage": "add_filter( 'bricks/wpml/exclude_controls_from_translation', function( $excluded_keys, $element, $control, $key ) {\n $excluded_keys[] = 'my_untranslated_control';\n\n\n return $excluded_keys;\n}, 10, 4 );"
}
前言
筛选从 WPML 翻译中排除的 Bricks 控件键。返回在当前元素/控件上下文中不应被翻译的控件键。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/wpml/exclude_controls_from_translation', function( $excluded_keys, $element, $control, $key ) {
$excluded_keys[] = 'my_untranslated_control';
return $excluded_keys;
}, 10, 4 );
参数
$excluded_keys (array):从翻译中排除的控件键。
$element (array):Bricks 元素数据。
$control (array):控件定义。
$key (string):当前的控件键或 repeater 字段键。
示例代码
筛选返回值
add_filter( 'bricks/wpml/exclude_controls_from_translation', function( $excluded_keys, $element, $control, $key ) {
$excluded_keys[] = 'my_untranslated_control';
return $excluded_keys;
}, 10, 4 );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/wpml/exclude_controls_from_translation', function( $value, $excluded_keys ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。