Bricks 中文文档:bricks/svg/allowed_tags

标签TAGS: 

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

📄 原始资料  |  展开查看原始 JSON(bricks-svg-allowed_tags.json)
{
  "name": "bricks/svg/allowed_tags",
  "kind": "filter",
  "url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-svg-allowed_tags/",
  "scraped_at": "2026-08-29",
  "hook_name": "bricks/svg/allowed_tags",
  "description": {
    "en": "Filters the list of allowed SVG tags during sanitization. This is used by the Bricks SVG sanitizer to ensure that uploaded or rendered SVGs do not contain malicious tags.",
    "zh": "筛选清理过程中允许的 SVG 标签列表。由 Bricks SVG 清理器使用,以确保上传或渲染的 SVG 不包含恶意标签。"
  },
  "parameters": [
    {
      "name": "tags",
      "type": "array",
      "type_zh": null,
      "description": {
        "en": "Array of allowed SVG tags.",
        "zh": "允许的 SVG 标签数组。"
      }
    }
  ],
  "example_usage": "add_filter( 'bricks/svg/allowed_tags', function( $tags ) {\n    // Example: Allow 'foreignObject' tag (use with caution!)\n    $tags[] = 'foreignObject';\n\n\n    return $tags;\n} );"
}

前言

筛选清理过程中允许的 SVG 标签列表。由 Bricks SVG 清理器使用,以确保上传或渲染的 SVG 不包含恶意标签。

用法

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

add_filter( 'bricks/svg/allowed_tags', function( $tags ) {
    // Example: Allow 'foreignObject' tag (use with caution!)
    $tags[] = 'foreignObject';


    return $tags;
} );

参数

  • $tags (array):允许的 SVG 标签数组。

示例代码

筛选返回值

add_filter( 'bricks/svg/allowed_tags', function( $tags ) {
    // Example: Allow 'foreignObject' tag (use with caution!)
    $tags[] = 'foreignObject';


    return $tags;
} );

根据条件短路返回原值

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

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

补充说明

更多细节可参考 官方文档