Last few years the community has been trying to make WordPress easier for all. Developers are trying to improve each and every functions for plugin and theme development. For long time they are working with document title and trying to improved
wp_title() to something more manageable from plugin or theme. Because by the old way, it was so hard to manage the document title from plugin or theme as mostly we were hard coded the functionality like following:<title>
<?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
wp_title( '|', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );
?>
</title>
Sometimes we added one or more functions in our functions.php file to manage our document title which is absolutely impossible to controll the document title from other plugin or theme.
WordPress 4.1 recommended the way for themes to display document titles is by adding theme support like following:
function theme_slug_setup() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'theme_slug_setup' );
Support should be added on the
after_setup_theme or init action and it does not accept any further arguments.
In upcoming version of WordPress (4.4),
wp_title() is deprecating and replacing with a more comprehensive way to generate titles. 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_titleshort-circuitswp_get_document_title()if it returns anything other than an empty value.document_title_separatorfilters the separator between title parts.document_title_partsfilters 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;




