pre_get_block_template
云策文档标注
概述
pre_get_block_template 是一个 WordPress 过滤器,用于在查询块模板对象之前拦截并修改它。开发者可以通过此 Hook 返回自定义的 WP_Block_Template 对象来绕过默认查询。
关键要点
- 过滤器名称:pre_get_block_template
- 作用时机:在查询块模板对象之前执行
- 参数:$block_template(WP_Block_Template 或 null)、$id(模板唯一标识符)、$template_type(模板类型,如 'wp_template' 或 'wp_template_part')
- 返回值:返回非 null 值可短路默认查询,返回 null 则允许 WordPress 执行正常查询
- 相关函数:get_block_template() 用于检索统一的模板对象
- 引入版本:WordPress 5.9.0
原文内容
Filters the block template object before the query takes place.
Description
Return a non-null value to bypass the WordPress queries.
Parameters
$block_templateWP_Block_Template|null-
Return block template object to short-circuit the default query, or null to allow WP to run its normal queries.
$idstring-
Template unique identifier (example:
'theme_slug//template_slug'). $template_typestring-
Template type. Either
'wp_template'or'wp_template_part'.
Source
$block_template = apply_filters( 'pre_get_block_template', null, $id, $template_type );
Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |