admin_head │ action-hook │ WP 2.1.0

Fires inside the <head> section on all WordPress admin pages.

Use it to output inline CSS/JS or other HTML markup. The callback does not receive any arguments.

The hook fires on all admin pages. If necessary, limit the output with get_current_screen().

Use admin_enqueue_scripts to enqueue separate CSS and JS files.

Usage

add_action( 'admin_head', 'wp_kama_admin_head_action' );

/**
 * Function for `admin_head` action-hook.
 * 
 * @return void
 */
function wp_kama_admin_head_action(){
	// action...
}

Examples

#1 Add CSS to the admin dashboard

Hide the setting for displaying the welcome panel.

add_action( 'admin_head', 'wp_kama_hide_welcome_panel_option' );

function wp_kama_hide_welcome_panel_option() {
	$screen = get_current_screen();

	if ( ! $screen || 'dashboard' !== $screen->id ) {
		return;
	}

	?>
	<style>
		[for="wp_welcome_panel-hide"] {
			display: none !important;
		}
	</style>
	<?php
}

#2 Add JavaScript to the admin area

add_action( 'admin_head', 'wp_kama_admin_head_script' );

function wp_kama_admin_head_script() {
	?>
	<script>
		console.log( 'Admin page loaded' );
	</script>
	<?php
}

Changelog

Since 2.1.0 Introduced.

Where the hook is called

In file: /wp-admin/admin-header.php
admin_head
wp-admin/admin-header.php 168
do_action( 'admin_head' );
wp-admin/includes/media.php 609
do_action( 'admin_head' );
wp-admin/includes/template.php 2175
do_action( 'admin_head' );

Where the hook is used in WordPress

wp-admin/export.php 46
add_action( 'admin_head', 'export_add_js' );
wp-admin/includes/admin-filters.php 42
add_action( 'admin_head', 'wp_color_scheme_settings' );
wp-admin/includes/admin-filters.php 48
add_action( 'admin_head', 'wp_admin_canonical_url' );
wp-admin/includes/admin-filters.php 49
add_action( 'admin_head', 'wp_site_icon' );
wp-admin/includes/admin-filters.php 50
add_action( 'admin_head', 'wp_admin_viewport_meta' );
wp-admin/network/settings.php 44
add_action( 'admin_head', 'network_settings_add_js' );
wp-admin/options-general.php 25
add_action( 'admin_head', 'options_general_add_js' );
wp-admin/options-reading.php 20
add_action( 'admin_head', 'options_reading_add_js' );
wp-includes/build/pages/font-library/page.php 128
remove_action( 'admin_head', 'wp_admin_bar_header' );
wp-includes/build/pages/options-connectors/page.php 128
remove_action( 'admin_head', 'wp_admin_bar_header' );
wp-includes/class-wp-admin-bar.php 55
add_action( 'admin_head', 'wp_admin_bar_header' );
wp-includes/default-filters.php 648
add_action( 'admin_head', 'wp_check_widget_editor_deps' );
wp-includes/general-template.php 5368
add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
wp-includes/theme-previews.php 91
add_action( 'admin_head', 'wp_block_theme_activate_nonce' );