The admin_footer WordPress PHP action allows you to print scripts or data before the default footer scripts in the WordPress admin area.
Usage
add_action('admin_footer', 'your_custom_function_name'); function your_custom_function_name() { // your custom code here echo $data; }
Parameters
$data
(string) – The data you want to print before the default footer scripts.
More information
See WordPress Developer Resources: admin_footer
Examples
Add a custom script to the admin footer
This example adds a simple JavaScript alert in the admin footer.
add_action('admin_footer', 'add_custom_admin_footer_script'); function add_custom_admin_footer_script() { echo "<script>alert('Hello from the admin footer!');</script>"; }
Add custom CSS to the admin footer
This example adds custom CSS to style an element in the WordPress admin area.
add_action('admin_footer', 'add_custom_admin_footer_css'); function add_custom_admin_footer_css() { echo '<style>.example-class { color: red; }</style>'; }
Print the current user’s information in the admin footer
This example prints the current logged-in user’s information in the admin footer.
add_action('admin_footer', 'print_current_user_info'); function print_current_user_info() { $current_user = wp_get_current_user(); echo 'Logged in as: ' . $current_user->display_name; }
Add a “Back to top” button in the admin footer
This example adds a “Back to top” button to the admin footer.
add_action('admin_footer', 'add_back_to_top_button'); function add_back_to_top_button() { echo '<a href="#" class="back-to-top" style="position: fixed; bottom: 20px; right: 20px;">Back to top</a>'; echo "<script>document.querySelector('.back-to-top').addEventListener('click', () => window.scrollTo(0, 0));</script>"; }
Display the number of published posts in the admin footer
This example displays the total number of published posts in the admin footer.
add_action('admin_footer', 'display_published_posts_count'); function display_published_posts_count() { $count_posts = wp_count_posts(); echo 'Published posts: ' . $count_posts->publish; }