钩子文档

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.

More Information

admin_footer-($hook_suffix) is triggered at the end of the section of a specific admin page, after `admin_footer` and `admin_print_footer_scripts` actions.

The hookname part you can get using the variable $GLOBALS['hook_suffix']. Examples of actions:

add_action('admin_footer-edit.php', 'my_post_list_page_hook'); // Fired on the page with the posts table
add_action('admin_footer-post.php', 'my_post_edit_page_hook'); // Fired on post edit page
add_action('admin_footer-post-new.php', 'my_new_post_page_hook'); // Fired on add new post page

This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn’t return, and shouldn’t take any parameters.

Source

do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

Changelog

Version Description
2.8.0 Introduced.

User Contributed Notes