Using WordPress ‘admin_footer-{$hook_suffix}’ PHP action

The admin_footer-{$hook_suffix} WordPress PHP action allows you to print scripts or data after the default footer scripts on admin pages.

Usage

add_action('admin_footer-{$hook_suffix}', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • $hook_suffix (string) – A dynamic portion of the hook name that refers to the global hook suffix of the current page.

More information

See WordPress Developer Resources: admin_footer-{$hook_suffix}

Examples

Add a custom JavaScript script to the footer of the “Add New Post” page

add_action('admin_footer-post-new.php', 'add_custom_script');
function add_custom_script() {
    echo '<script>alert("Welcome to the Add New Post page!");</script>';
}
add_action('admin_footer-widgets.php', 'add_custom_styles');
function add_custom_styles() {
    echo '<style>.widget-liquid-left { background-color: #f5f5f5; }</style>';
}
add_action('admin_footer-upload.php', 'add_custom_message');
function add_custom_message() {
    echo '<p style="text-align: center;">Remember to optimize images before uploading!</p>';
}

Add a custom script to the footer of the “Edit Post” page, only for a specific post ID

add_action('admin_footer-post.php', 'add_script_for_specific_post');
function add_script_for_specific_post() {
    global $post;
    if ($post->ID == 42) {
        echo '<script>alert("You are editing post ID 42!");</script>';
    }
}
add_action('admin_footer', 'add_custom_js_to_all_admin_pages');
function add_custom_js_to_all_admin_pages() {
    echo '<script>console.log("Custom JS loaded on all admin pages.");</script>';
}