📄 原始资料 | 展开查看原始 JSON(bricks-resolve_attachment_id.json){ “name”: “bricks/resolve_attachment_id”, “kind”: “filter”, “url”: “https://academy.bricksbuilder.io/developer/hooks/filters/bricks-resolve_attachment_id/”, “scraped_at”: “2026-08-29”, “hook_name”: “bricks/resolve_attachment_id”, “de…
📄 原始资料 | 展开查看原始 JSON(bricks-resolve_attachment_id.json)
{
"name": "bricks/resolve_attachment_id",
"kind": "filter",
"url": "https://academy.bricksbuilder.io/developer/hooks/filters/bricks-resolve_attachment_id/",
"scraped_at": "2026-08-29",
"hook_name": "bricks/resolve_attachment_id",
"description": {
"en": "Filters an attachment ID before Bricks uses it for frontend output. This is useful for multilingual plugins or media integrations that need to resolve translated attachment IDs. Bricks casts the filtered value with absint() . If the filtered value is empty or invalid, Bricks keeps the original attachment ID so image output does not break.",
"zh": "在 Bricks 使用附件 ID 进行前端输出之前对其进行筛选。这对于多语言插件或媒体集成很有用,它们需要解析已翻译的附件 ID。Bricks 使用 absint() 转换筛选后的值。如果筛选后的值为空或无效,Bricks 会保留原始附件 ID,以免图像输出中断。"
},
"parameters": [
{
"name": "attachment_id",
"type": "int",
"type_zh": null,
"description": {
"en": "The attachment post ID Bricks is about to use.",
"zh": "Bricks 即将使用的附件文章 ID。"
}
}
],
"example_usage": "add_filter( 'bricks/resolve_attachment_id', function( $attachment_id ) {\n return $attachment_id;\n} );"
}
前言
在 Bricks 使用附件 ID 进行前端输出之前对其进行筛选。这对于多语言插件或媒体集成很有用,它们需要解析已翻译的附件 ID。Bricks 使用 absint() 转换筛选后的值。如果筛选后的值为空或无效,Bricks 会保留原始附件 ID,以免图像输出中断。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/resolve_attachment_id', function( $attachment_id ) {
return $attachment_id;
} );
参数
$attachment_id (int):Bricks 即将使用的附件文章 ID。
示例代码
筛选返回值
add_filter( 'bricks/resolve_attachment_id', function( $attachment_id ) {
return $attachment_id;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/resolve_attachment_id', function( $value, $attachment_id ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。