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

The admin_head-{$hook_suffix} WordPress PHP action fires in the head section for a specific admin page. The dynamic portion of the hook name, $hook_suffix, refers to the hook suffix for the admin page.

Usage

add_action('admin_head-{$hook_suffix}', 'your_custom_function');

function your_custom_function() {
    // your custom code here
}

Parameters

  • $hook_suffix (string): The hook suffix for the admin page, which is used to target specific pages in the admin area.

More information

See WordPress Developer Resources: admin_head-{$hook_suffix}

Examples

Add custom CSS to a specific admin page

Add custom CSS to the head section of the “Edit Post” admin page.

add_action('admin_head-post.php', 'add_custom_css_to_edit_post');

function add_custom_css_to_edit_post() {
    echo '<style>
        /* your custom CSS here */
    </style>';
}

Add custom JavaScript to a specific admin page

Add custom JavaScript to the head section of the “Media Library” admin page.

add_action('admin_head-upload.php', 'add_custom_js_to_media_library');

function add_custom_js_to_media_library() {
    echo '<script>
        // your custom JavaScript here
    </script>';
}

Change the admin page title for a specific admin page

Modify the page title of the “Widgets” admin page.

add_action('admin_head-widgets.php', 'change_widgets_page_title');

function change_widgets_page_title() {
    echo '<script>
        document.title = "Custom Widgets Page Title";
    </script>';
}

Add favicon to a specific admin page

Add a custom favicon to the head section of the “Plugins” admin page.

add_action('admin_head-plugins.php', 'add_favicon_to_plugins_page');

function add_favicon_to_plugins_page() {
    echo '<link rel="shortcut icon" href="https://example.com/favicon.ico" />';
}

Add custom meta tags to a specific admin page

Add custom meta tags to the head section of the “Settings” admin page.

add_action('admin_head-options-general.php', 'add_custom_meta_tags_to_settings_page');

function add_custom_meta_tags_to_settings_page() {
    echo '<meta name="robots" content="noindex, nofollow" />';
    echo '<meta name="description" content="Custom description for the settings page." />';
}

Add custom CSS to style the personal options

This example adds custom CSS to style the personal options section.

add_action('admin_head-profile.php', 'add_custom_css');
function add_custom_css() {
    echo '<style>
        /* Your custom CSS here */
    </style>';
}