Bricks 中文文档:bricks/template_preview/supported_content_types

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

📄 原始资料  |  展开查看原始 JSON(bricks-template_preview-supported_content_types.json)
{
  "name": "bricks/template_preview/supported_content_types",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-template_preview-supported_content_types/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/template_preview/supported_content_types",
  "description": {
    "en": "Filters the list of content types available for selection in the “Populate Content” (Template Preview) setting. This allows you to add custom preview contexts.",
    "zh": "筛选“填充内容(Populate Content)”(模板预览)设置中可供选择的内容类型列表。允许你添加自定义预览上下文。"
  },
  "parameters": [
    {
      "name": "types",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Associative array where keys are the content type IDs and values are their labels.",
        "zh": "关联数组,键为内容类型 ID,值为对应的标签。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/template_preview/supported_content_types', function( $types ) {\n    // Example: Add a custom preview type\n    $types['my_custom_preview'] = esc_html__( 'My Custom Preview', 'my-plugin' );\n\n\n    return $types;\n} );"
}

前言

筛选“填充内容(Populate Content)”(模板预览)设置中可供选择的内容类型列表。允许你添加自定义预览上下文。

用法

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

add_filter( 'bricks/template_preview/supported_content_types', function( $types ) {
    // Example: Add a custom preview type
    $types['my_custom_preview'] = esc_html__( 'My Custom Preview', 'my-plugin' );


    return $types;
} );

参数

  • $types (array):关联数组,键为内容类型 ID,值为对应的标签。

示例代码

筛选返回值

add_filter( 'bricks/template_preview/supported_content_types', function( $types ) {
    // Example: Add a custom preview type
    $types['my_custom_preview'] = esc_html__( 'My Custom Preview', 'my-plugin' );


    return $types;
} );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档