钩子文档

admin_footer

💡 云策文档标注

概述

admin_footer 是一个 WordPress 管理后台专用的 Hook,用于在默认页脚脚本之前输出脚本或数据。它仅适用于管理界面,不能在前端使用。

关键要点

  • admin_footer 是一个 Action Hook,在 admin-footer.php 页面的 </body> 标签关闭后、admin_print_footer_scripts 动作调用前触发。
  • 此 Hook 仅用于管理后台,不能在前端添加任何内容。
  • 使用 add_action('admin_footer', 'your_function') 来挂载自定义函数,函数应直接输出数据而非返回。
  • 可以通过 add_action 的第三个参数设置优先级,数字越低优先级越高。

代码示例

// 示例:在管理页脚输出 HTML
function my_admin_footer_function() {
    echo '<div>' . __( 'This will be inserted at the bottom of admin page', 'textdomain' ) . '</div>';
}
add_action('admin_footer', 'my_admin_footer_function');

// 示例:添加 JavaScript 函数
function my_admin_footer_js() {
    echo '<script>alert("This will trigger an alert on the admin page.");</script>';
}
add_action('admin_footer', 'my_admin_footer_js');

// 示例:设置优先级
function my_admin_footer_priority() {
    echo '<div>This will be inserted at the bottom of admin page</div>';
}
add_action('admin_footer', 'my_admin_footer_priority', 5); // 优先级为 5

注意事项

  • 函数应使用 echo 输出数据,而不是 return,否则内容不会显示。
  • 确保仅在管理后台使用此 Hook,避免影响前端性能或功能。

📄 原文内容

Prints scripts or data before the default footer scripts.

Parameters

$datastring
The data to print.

More Information

The admin_footer action is triggered just after closing the

tag and right before admin_print_footer_scripts action call of the admin-footer.php page.

This hook is for admin only and can’t be used to add anything on the front end.

Source

do_action( 'admin_footer', '' );

Changelog

Version Description
1.2.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.