apply_filters( 'document_title_parts', array $title )
Filters the parts of the document title.
Description Description
Parameters Parameters
- $title
-
(array) The document title parts.
- 'title'
(string) Title of the viewed page. - 'page'
(string) Optional. Page number if paginated. - 'tagline'
(string) Optional. Site description when on home page. - 'site'
(string) Optional. Site title when not on home page.
- 'title'
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Change the title for a specific page ID:
add_filter( 'document_title_parts', function( $title_parts_array ) { if ( get_the_ID() == 2055 ) { $title_parts_array['title'] = 'Custom Page Title'; } return $title_parts_array; } );Make sure your add_filter() comes before the get_header() in your template file if you adding a title filter for that template file.
<?php // This filter must be above get_header() to work correctly add_filter('document_title_parts', 'callbackFunctionName'); get_header(); ...Feedback
It’s bad practice to do
add_filterin your template file. These kind of calls should live in your theme’sfunctions.phpfile instead. — By infostreams —