bueltge/wordpress-basis-theme

wp_title Support

bueltge opened this issue · 0 comments

Changes for WP 4.1 at wp_title()

Add support in inc/setup.php

/**
 * 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' );

Remove Markup and title in templates, like single.php

<title><?php wp_title( '|', true, 'right' ); ?></title>

Backwards compatibility

To enable support in existing themes without breaking backwards compatibility, 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() {
    echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
}
add_action( 'wp_head', 'theme_slug_render_title' );
endif;

This would also be the place to optionally add a filter to enhance the document title, along the lines of what recent default themes have been doing.

Background

https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/