do_action( 'wp_head' )

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

Description Description

Source Source

File: wp-includes/general-template.php

View on Trac

Top ↑

Changelog Changelog

Version Description
1.5.0 Introduced.

Top ↑

More Information 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.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Aurovrata Venet

    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 hool 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');

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