Filter Hook since 4.4.0
document_title_parts
Filters the parts that build the <title> tag on modern themes
Description
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.
When it runs
Inside wp_get_document_title(), called from _wp_render_title_tag() on wp_head with priority 1.
Signature
apply_filters( 'document_title_parts', array $title );Parameters
$titlearray — Associative array with keys like title, page, tagline, site.
Examples
Basic
add_filter( 'document_title_parts', function( $title ) {
if ( is_singular( 'book' ) ) {
$title['title'] .= ' | Book Review';
}
return $title;
} );Append a label to the title on a single custom post type view.
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
Common mistakes
- Hooking wp_title on a modern/block theme — it never calls wp_title(); use document_title_parts instead
Related hooks
FAQ
Why doesn't my wp_title filter work on this theme?
Modern themes render the title via wp_get_document_title(), which uses document_title_parts — wp_title() usually isn't called at all.
Source: wp-includes/general-template.php