Skip to content

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

document_title_parts

Filters the pieces WordPress joins to make the page's <title>: the title, page number, tagline and site name.

  • Type Filter
  • From WordPress
  • Since 4.4.0
  • Fired in wp-includes/general-template.php

When it fires

WordPress applies document_title_parts in wp_get_document_title(), which prints the tag in the . Block themes always use it; classic themes use it when they declare add_theme_support( 'title-tag' ).

The array can hold 'title', 'page' (from page 2 on), 'tagline' (front page only) and 'site' (every other page). WordPress joins what's left with the separator from document_title_separator.

Parameters

Parameters
$titlearray The document title parts: 'title' (title of the viewed page), 'page' (optional, page number if paginated), 'tagline' (optional, site description on the home page) and 'site' (optional, site title when not on the home page).

What to return

The array of title parts. Remove keys you don't want or change their values.

Example: Drop the tagline from the front page title

PHP
add_filter( 'document_title_parts', function ( $title ) {
	if ( is_front_page() ) {
		unset( $title['tagline'] );
	}
	return $title;
} );

Good to know

  • SEO plugins usually set the title through pre_get_document_title, and then this filter never runs. Change the title in the SEO plugin's settings instead.
  • To change the dash between the parts, use the document_title_separator filter.
  • It doesn't change the heading shown on the page itself; for that, see the_title.

Move your snippets over this afternoon.

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