WordPress added support for the title-tag
feature in version 4.1 and it’s now a required feature for themes uploaded to the repo.
To implement this feature, make sure your theme does not have the title tag hard coded within header.php
, e.g.:
<title><?php wp_title( '|', true, 'right' ); ?></title>
Configure your theme with title-tag support like this:
add_action( 'after_setup_theme', 'wpse_theme_setup' );
function wpse_theme_setup() {
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
}
To make changes to the title text, use the following filters (source):
-
pre_get_document_title
short-circuitswp_get_document_title()
if it
returns anything other than an empty value. -
document_title_separator
filters the separator between title parts. -
document_title_parts
filters the parts that make up the document
title, passed in an associative array.