Head & Meta

The hooks that shape what actually ships in the document head, footer, and body tag. This is where themes and plugins inject meta tags, scripts, and classes without touching template files directly. 2 actions, 3 filters in this category.

wp_head

head-meta

Outputs content in the <head> section

wp_head is the print slot inside document head. Use it for meta tags and inline snippets — not for enqueueing CSS or JS files.

Signature

do_action( 'wp_head' );

Example

add_action( 'wp_head', function() {
    echo '<meta name="theme-color" content="#0073aa">';
} );

Common Use Cases

  • Enqueue custom meta tags
  • Output inline styles or scripts
  • Add Open Graph / SEO tags
  • Insert tracking pixels
since 1.5.0wp-includes/general-template.php

document_title_parts

head-meta

Filters the parts that build the <title> tag on modern themes

document_title_parts is the modern replacement for wp_title — it works with an array of parts, not a raw string, so you edit pieces instead of parsing text.

Signature

apply_filters( 'document_title_parts', array $title );

Example

add_filter( 'document_title_parts', function( $title ) {
    if ( is_singular( 'book' ) ) {
        $title['title'] .= ' | Book Review';
    }
    return $title;
} );

Common Use Cases

  • Customize SEO page titles per post type
  • Remove the tagline/site name segment
  • Add dynamic segments (category, search term)
  • Override the title on 404 pages
since 4.4.0wp-includes/general-template.php

wp_title

head-meta

Filters the document <title> tag

wp_title is the classic document-title filter. Modern themes should prefer document_title_parts — this hook remains for older title tags.

Signature

apply_filters( 'wp_title', string $title, string $sep, string $seplocation );

Example

add_filter( 'wp_title', function( $title, $sep ) {
    return $title . $sep . get_bloginfo( 'name' );
}, 10, 2 );

Common Use Cases

  • Customize SEO page titles on legacy themes
  • Append site name to titles
  • Set title format for specific pages
  • Override title for 404 pages
since 0.71wp-includes/general-template.php

body_class

head-meta

Filters the CSS classes on <body>

body_class lets CSS target context without extra wrappers. Return the array — do not echo class names.

Signature

apply_filters( 'body_class', string[] $classes, string[] $css_class );

Example

add_filter( 'body_class', function( $classes ) {
    if ( is_user_logged_in() ) {
        $classes[] = 'user-logged-in';
    }
    return $classes;
} );

Common Use Cases

  • Add role-based body classes
  • Target specific page templates via CSS
  • Add device detection classes
  • Inject A/B test variant classes
since 2.8.0wp-includes/post-template.php

wp_footer

head-meta

Fires before </body> closing tag

wp_footer is the last print slot on the front-end. Deferred scripts, analytics, and widgets that must load after content belong here.

Signature

do_action( 'wp_footer' );

Example

add_action( 'wp_footer', function() {
    echo '<script>console.log("Footer loaded");</script>';
} );

Common Use Cases

  • Inject deferred JavaScript
  • Add analytics snippets
  • Load chat widgets
  • Output footer-specific markup
since 1.5.1wp-includes/general-template.php