Introduce a new means of outputting a <title> tag in the theme head. Requires a theme to add support by calling add_theme_support( 'title-tag' ). This is the first step in adding a more robust means of generating and outputting the title tag.

See #18548.
Props obenland, chrisbliss18, joostdevalk.



git-svn-id: https://develop.svn.wordpress.org/trunk@30074 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2014-10-28 21:11:11 +00:00
parent 1e8635fcea
commit efb9cd0cc5
3 changed files with 51 additions and 1 deletions

View File

@@ -730,6 +730,25 @@ function get_bloginfo( $show = '', $filter = 'raw' ) {
return $output;
}
/**
* Display <title> tag with contents.
*
* @since 4.1.0
* @access private
*/
function _wp_render_title_tag() {
if ( ! current_theme_supports( 'title-tag' ) ) {
return;
}
// This can only work internally on wp_head.
if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
return;
}
echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
}
/**
* Display or retrieve page title for all areas of blog.
*
@@ -753,7 +772,7 @@ function get_bloginfo( $show = '', $filter = 'raw' ) {
* @return string|null String on retrieve, null when displaying.
*/
function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
global $wp_locale;
global $wp_locale, $page, $paged;
$m = get_query_var('m');
$year = get_query_var('year');
@@ -853,6 +872,19 @@ function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
$title = $prefix . implode( " $sep ", $title_array );
}
if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
$title .= get_bloginfo( 'name', 'display' );
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
}
}
/**
* Filter the text of the page title.
*