get_footer
云策文档标注
概述
get_footer 是一个 WordPress Hook,在 get_footer() 函数调用开始时触发,用于在加载页脚模板文件之前执行代码。它允许开发者根据特定页脚文件名称定制操作。
关键要点
- Hook 名称:get_footer,在 get_footer() 函数开始时触发。
- 参数:$name(字符串或 null,指定页脚文件名称,默认为 null 使用默认页脚),$args(数组,传递给页脚模板的额外参数)。
- 用途:适合设置和执行不会立即输出到浏览器的代码,避免在页面标记显示前输出内容。
- 添加方式:通过 add_action 在 functions.php 文件中添加动作。
- 版本历史:$args 参数在 5.5.0 版本添加,$name 参数在 2.8.0 版本添加,Hook 在 2.1.0 版本引入。
代码示例
function themeslug_footer_hook( $name ) {
if ( 'new' == $name ) {
// 条件性显示脚本,例如针对 footer-new.php 模板
}
}注意事项
此 Hook 最适合用于设置和执行不会立即回显到浏览器的代码,任何回显内容都会在页面标记显示之前出现。
原文内容
Fires before the footer template file is loaded.
Parameters
$namestring|null-
Name of the specific footer file to use. Null for the default footer.
$argsarray-
Additional arguments passed to the footer template.
Source
do_action( 'get_footer', $name, $args );
Skip to note 2 content
Collins Mbaka
The following example will display a script conditionally for a different footer. This is just one example of how you may use the hook and will use a secondary template file of footer-new.php