Filter Hook since 0.71
wp_title
Filters the document <title> tag
Description
wp_title is the classic document-title filter. Modern themes should prefer document_title_parts — this hook remains for older title tags.
When it runs
When wp_title() is called directly by a theme's header.php. Block/modern themes usually use document_title_parts instead.
Signature
apply_filters( 'wp_title', string $title, string $sep, string $seplocation );Parameters
$titlestring — Title text.$sepstring — Separator.$seplocationstring — left or right.
Examples
Basic
add_filter( 'wp_title', function( $title, $sep ) {
return $title . $sep . get_bloginfo( 'name' );
}, 10, 2 );Append the site name to the classic title output.
Real case
add_filter( 'wp_title', function( $title, $sep, $seplocation ) {
if ( is_feed() ) {
return $title;
}
return 'left' === $seplocation ? get_bloginfo( 'name' ) . " $sep $title" : $title;
}, 10, 3 );Skip the filter for feeds and control separator placement manually.
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
Common mistakes
- Hooking wp_title on a block/modern theme that never calls wp_title() — use document_title_parts instead
Related hooks
FAQ
Is the wp_title filter deprecated?
The wp_title() template tag is legacy — modern themes render titles via wp_get_document_title() and the document_title_parts filter. wp_title only fires if a theme still calls wp_title() directly in header.php.
Source: wp-includes/general-template.php