Document title in 4.4

WordPress 4.1 introduced a way for themes to support a new way of rendering the document title, letting Core handle its generation and output. The next step followed just recently (#31078), deprecating wp_title() and replacing it with a more comprehensive way to generate titles.

UPDATE 12 November – wp_title has been reinstated until alternative usages have been identified and a path forward for them defined.

Plugin authors can now check for theme support and have a few new filters available that will allow them to change or replace the title in a reliable way:

  • 'pre_get_document_title' short-circuits wp_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.

This latest change makes the new API (almost) feature complete and theme authors are discouraged from using wp_title() in the future. If it was decided to add a UI to let users choose the make up of their document title, or another improvement to how title generation works, we now have a forward compatible way to handle these things.

To upgrade themes from using wp_title() to declaring theme support for core’s title-tag without breaking backwards compatibility with WordPress 4.0 and older, theme authors can check if the callback function exists and add a shiv in case it does not:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
	function theme_slug_render_title() {
?>
<title><?php wp_title( '-', true, 'right' ); ?></title>
<?php
	}
	add_action( 'wp_head', 'theme_slug_render_title' );
endif;

#4-4, #dev-notes, #wp_title