Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/wp head


The wp_head action hook is triggered within the <head></head> section of the user's 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.

This function is simply a wrapper for:


This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn't return, and shouldn't take any parameters.

This hook is theme-dependent which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it.

This hook is an action which means that it primarily acts as an event trigger, instead of a content filter. This is a semantic difference, but it will help you to remember what this hook does if you use it like this:

add_action('wp_head', 'your_function');

See Plugin API - Actions for more detail.

Default 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.


Add custom css within head section using wp_head action.

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

Add custom javascript within head section using wp_head action.

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

Source File

wp_head action hook is located in wp-includes/general-template.php

See also

This page is marked as incomplete. You can help Codex by expanding it.