admin_head

Home » Hooks » admin_head

The WordPress hook ‘admin_head’ is a powerful tool that allows developers to modify the content of the WordPress Admin area’s HTML head section. This hook is fired just before the head section of the page is printed. It provides a way to insert custom code, such as CSS styles and JavaScript, in the head section.

The ‘admin_head’ hook is typically used to add styles and scripts to the WordPress Admin area’s pages. This hook is particularly useful for developers who are building custom WordPress plugins and themes as it allows them to add their own custom code to the WordPress Admin area.

Here’s an example of how to use the ‘admin_head’ hook to add a custom CSS style to the WordPress Admin area:

function my_custom_admin_styles() {
  echo '<style>
    #wpadminbar {
      background-color: #333;
      color: #fff;
    }
  </style>';
}

add_action('admin_head', 'my_custom_admin_styles');

In this example, we’ve defined a custom function called ‘my_custom_admin_styles’ that outputs a custom CSS style which sets the background color of the WordPress Admin bar to #333 and changes the color of the text to white. We then use the ‘add_action’ function to hook this custom function onto the ‘admin_head’ hook, so that it will be executed when the hook is fired.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.