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

  • $title array — 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

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

document_title_parts → wp_title

functions.php — document_title_parts
functions.php
PHP document_title_parts · Hook 1 of 2 · Step 1 of 6

Practice the document_title_parts WordPress filter hook in our interactive sandbox — a VS Code-style editor with a step-by-step document_title_parts tutorial, add_filter exercises, and instant feedback. No local WordPress install required.