do_action( ‘wp_head’ )

Prints scripts or data in the head tag on the front end.

More Information

The wp_head action hook is triggered within the <head></head> section of the theme’s header.php template by the wp_head() function.

Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported. See the Plugin API Hooks page on the Theme handbook for more information.

WordPress core uses this hook to perform many actions. Most of default actions into the 'wp-head' hook by WordPress core are set up in wp-includes/default-filters.php. If you need to remove a default hook, this file will give you the priority for which to use to remove the hook.


do_action( 'wp_head' );



User Contributed Notes

  1. Skip to note 3 content

    taken from the old codex pages:

    function hook_css() {
                .wp_head_example {
                    background-color : #f1f1f1;
    add_action('wp_head', 'hook_css');

    or for inline scripts which need to be placed in the head,

    function hook_javascript() {
                alert('Page is loading...');
    add_action('wp_head', 'hook_javascript');

    The wp_head() function which ones sees in all header.php files, is simply triggering the hook do_action(‘wp_head’). WordPress core files then hooks it multiple times to print the head,

    add_action( 'wp_head',             '_wp_render_title_tag',            1     );
    add_action( 'wp_head',             'wp_enqueue_scripts',              1     );
    add_action( 'wp_head',             'wp_resource_hints',               2     );
    add_action( 'wp_head',             'feed_links',                      2     );
    add_action( 'wp_head',             'feed_links_extra',                3     );
    add_action( 'wp_head',             'rsd_link'                               );
    add_action( 'wp_head',             'wlwmanifest_link'                       );
    add_action( 'wp_head',             'adjacent_posts_rel_link_wp_head', 10, 0 );
    add_action( 'wp_head',             'locale_stylesheet'                      );
    add_action( 'wp_head',             'noindex',                          1    );
    add_action( 'wp_head',             'print_emoji_detection_script',     7    );
    add_action( 'wp_head',             'wp_print_styles',                  8    );
    add_action( 'wp_head',             'wp_print_head_scripts',            9    );
    add_action( 'wp_head',             'wp_generator'                           );
    add_action( 'wp_head',             'rel_canonical'                          );
    add_action( 'wp_head',             'wp_shortlink_wp_head',            10, 0 );
    add_action( 'wp_head',             'wp_custom_css_cb',                101   );
    add_action( 'wp_head',             'wp_site_icon',                    99    );

    However, more interestingly you can also use it to add some meta tags,

    function hook_nocache() {
      <meta http-equiv="cache-control" content="max-age=0" />
      <meta http-equiv="cache-control" content="no-cache" />
      <meta http-equiv="expires" content="0" />
      <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
      <meta http-equiv="pragma" content="no-cache" />
    add_action('wp_head', 'hook_nocache');
  2. Skip to note 4 content

    Safe way to add HTML comment signature at the bottom page.

    add_action( 'wp_head', function() {
    	if ( ! is_user_logged_in() && ! defined( 'ADD_HTML_SIGNATURE' ) ) {
    		define( 'ADD_HTML_SIGNATURE', true );
    } );
    add_action( 'shutdown', function() {
    	if ( ! is_user_logged_in() && defined( 'ADD_HTML_SIGNATURE' ) ) {
    		echo "\n<!-- YOUR HTML SIGNATURE -->\n";
    }, 999 );

You must log in before being able to contribute a note or feedback.