admin_head │ action-hook │ WC 2.1.0

This is a WordPress - admin_head hook. The plugin just uses it.

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
}

Where the hook is called

WC_Admin_Setup_Wizard::setup_wizard_header()
admin_head

Where the hook is used in WooCommerce

woocommerce/includes/admin/class-wc-admin-exporters.php 37
add_action( 'admin_head', array( $this, 'hide_from_menus' ) );
woocommerce/includes/admin/class-wc-admin-exporters.php 38
add_action( 'admin_head', array( $this, 'menu_highlight_for_product_export' ) );
woocommerce/includes/admin/class-wc-admin-importers.php 35
add_action( 'admin_head', array( $this, 'hide_from_menus' ) );
woocommerce/includes/admin/class-wc-admin-importers.php 36
add_action( 'admin_head', array( $this, 'menu_highlight_for_product_import' ) );
woocommerce/includes/admin/settings/class-wc-settings-payment-gateways.php 55
add_action( 'admin_head', array( $this, 'hide_help_tabs' ) );
woocommerce/src/Admin/PageController.php 71
add_action( 'admin_head', array( $this, 'remove_app_entry_page_menu_item' ), 20 );
woocommerce/src/Blocks/DependencyDetection.php 88
add_action( 'admin_head', array( $this, 'output_early_proxy_setup' ), 1 );
woocommerce/src/Gateways/PayPal/Notices.php 79
add_action( 'admin_head', array( $this, 'add_paypal_notices_on_payments_settings_page' ) );
woocommerce/src/Internal/Admin/Coupons.php 49
add_action( 'admin_head', array( $this, 'fix_coupon_menu_highlight' ), 99 );
woocommerce/src/Internal/Admin/Homescreen.php 51
add_action( 'admin_head', array( $this, 'update_link_structure' ), 20 );
woocommerce/src/Internal/Admin/Loader.php 80
add_action( 'admin_head', array( __CLASS__, 'remove_notices' ) );
woocommerce/src/Internal/Admin/Loader.php 81
add_action( 'admin_head', array( __CLASS__, 'smart_app_banner' ) );
woocommerce/src/Internal/Admin/Notes/WooSubscriptionsNotes.php 31
add_action( 'admin_head', array( $this, 'admin_head' ) );
woocommerce/src/Internal/ComingSoon/ComingSoonAdminBarBadge.php 43
add_action( 'admin_head', array( $this, 'output_css' ) );