get_block_template
云策文档标注
概述
get_block_template 是一个 WordPress 过滤器,用于在获取块模板对象后对其进行修改。它允许开发者自定义查询到的块模板对象。
关键要点
- 这是一个过滤器,用于修改已获取的块模板对象。
- 参数包括 $block_template(块模板对象或 null)、$id(模板唯一标识符)和 $template_type(模板类型)。
- 在 WordPress 5.9.0 版本中引入。
代码示例
apply_filters( 'get_block_template', $block_template, $id, $template_type );注意事项
确保正确处理 $block_template 参数,因为它可能为 null。
原文内容
Filters the queried block template object after it’s been fetched.
Parameters
$block_templateWP_Block_Template|null-
The found block template, or null if there isn’t one.
$idstring-
Template unique identifier (example:
'theme_slug//template_slug'). $template_typestring-
Template type. Either
'wp_template'or'wp_template_part'.
Source
return apply_filters( 'get_block_template', $block_template, $id, $template_type );
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |