Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

wp_head

Fires inside the <head> of every front-end page. Use it to print meta tags, link tags or small inline scripts and styles.

  • Type Action
  • From WordPress
  • Since 1.5.0
  • Fired in wp-includes/general-template.php

When it fires

wp_head runs when the theme calls wp_head(), just before the closing tag. Classic themes call it in header.php and block themes get it automatically. It only fires on the front end: the admin area has admin_head and the login page has login_head.

WordPress uses this hook itself. At priority 1 it prints the tag and runs wp_enqueue_scripts, at 8 it prints stylesheets and at 9 the head scripts, so anything you print at the default priority 10 comes after them.

Parameters

None. Your callback takes no arguments.

Example: Add a site verification meta tag to the home page

PHP
add_action( 'wp_head', function () {
	if ( ! is_front_page() ) {
		return;
	}
	printf(
		'<meta name="google-site-verification" content="%s">' . "\n",
		esc_attr( 'paste-your-code-here' )
	);
} );

Good to know

  • To load a CSS or JavaScript file, enqueue it on wp_enqueue_scripts rather than printing a tag here. WordPress then handles dependencies and avoids loading it twice.
  • Use a priority below 8 if your output has to appear before the stylesheets.
  • Page caching stores the finished HTML. After changing the snippet, clear the cache to see the new output.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.