admin_footer-{$hook_suffix}
云策文档标注
概述
admin_footer-{$hook_suffix} 是一个 WordPress 动态 Hook,用于在特定管理页面的默认页脚脚本之后输出脚本或数据。它基于当前页面的全局 hook 后缀触发,适用于自定义后台页脚内容。
关键要点
- 这是一个动态 Hook,名称中的 $hook_suffix 对应当前页面的全局 hook 后缀,如 edit.php、post.php 等。
- Hook 在 admin_footer 和 admin_print_footer_scripts 动作之后触发,位于特定管理页面的 </body> 标签前。
- 使用 add_action 注册函数,函数应直接输出内容(如 echo),不返回任何值,也不接受参数。
- 可以通过 $GLOBALS['hook_suffix'] 获取当前页面的 hook 后缀,以动态绑定 Hook。
代码示例
add_action('admin_footer-post.php', 'my_post_edit_page_footer');
function my_post_edit_page_footer(){
echo "This paragraph will be shown in footer of the post edit page.";
}注意事项
- 此 Hook 自 WordPress 2.8.0 版本引入,无参数传递,函数应专注于输出或后台任务。
- 避免在函数中返回数据或定义参数,以确保正确执行。
原文内容
Prints scripts or data after the default footer scripts.
Description
The dynamic portion of the hook name, $hook_suffix, refers to the global hook suffix of the current page.
Source
do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
Akira Tachibana
(From Codex)
Show a paragraph in footer of post edit page
add_action( 'admin_footer-post.php', 'my_post_edit_page_footer' ); function my_post_edit_page_footer(){ echo "<p>This paragraph will be shown in footer of the post edit page.</p>"; }