document_title_parts
Filters the pieces WordPress joins to make the page's <title>: the title, page number, tagline and site name.
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
$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
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.