钩子文档

wp_after_load_template

💡 云策文档标注

概述

wp_after_load_template 是一个 WordPress 动作钩子,在模板文件加载后触发,允许开发者在模板加载后执行自定义代码。

关键要点

  • 这是一个动作钩子,用于在模板文件加载后执行操作。
  • 钩子传递三个参数:$_template_file(模板文件完整路径)、$load_once(是否使用 require_once)和 $args(传递给模板的额外参数)。
  • 钩子通过 do_action() 调用,位于 load_template() 函数中。
  • 首次引入于 WordPress 6.1.0 版本。

代码示例

do_action( 'wp_after_load_template', $_template_file, $load_once, $args );

注意事项

  • 钩子主要用于扩展模板加载后的功能,如日志记录、缓存处理或动态内容修改。
  • 确保在添加钩子时正确处理参数,以避免影响模板的正常加载。

📄 原文内容

Fires after a template file is loaded.

Parameters

$_template_filestring
The full path to the template file.
$load_oncebool
Whether to require_once or require.
$argsarray
Additional arguments passed to the template.

Source

do_action( 'wp_after_load_template', $_template_file, $load_once, $args );

Changelog

Version Description
6.1.0 Introduced.