钩子文档

get_block_file_template

💡 云策文档标注

概述

get_block_file_template 是一个 WordPress 过滤器钩子,用于在从主题文件(或插件注册)获取块模板对象后对其进行修改。它允许开发者在模板对象被返回前调整其属性或行为。

关键要点

  • 这是一个过滤器钩子,用于修改块模板对象。
  • 在模板从主题文件或插件注册中获取后触发。
  • 参数包括 $block_template(模板对象或 null)、$id(模板唯一标识符)和 $template_type(模板类型)。
  • 首次引入于 WordPress 5.9.0 版本。

代码示例

apply_filters( 'get_block_file_template', $block_template, $id, $template_type );

📄 原文内容

Filters the block template object after it has been (potentially) fetched from the theme file.

Parameters

$block_templateWP_Block_Template|null
The found block template, or null if there is none.
$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_file_template', $block_template, $id, $template_type );

Changelog

Version Description
5.9.0 Introduced.