diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 55c76665e0..e4feb4f333 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -196,6 +196,7 @@ add_filter( 'title_save_pre', 'trim' ); add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 ); // Actions +add_action( 'wp_head', '_wp_render_title_tag', 1 ); add_action( 'wp_head', 'wp_enqueue_scripts', 1 ); add_action( 'wp_head', 'feed_links', 2 ); add_action( 'wp_head', 'feed_links_extra', 3 ); diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 886ffc6e6c..4efe0f991f 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -730,6 +730,25 @@ function get_bloginfo( $show = '', $filter = 'raw' ) { return $output; } +/** + * Display 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' ) . "\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 = '»', $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 = '»', $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. * diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 632bac4015..2e432bcd83 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1611,6 +1611,15 @@ function add_theme_support( $feature ) { define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); break; + + // Ensure that 'title-tag' is accessible in the admin. + case 'title-tag' : + // Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. + if ( did_action( 'wp_loaded' ) ) { + _doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( _x( 'You need to add theme support before %s.', 'action name' ), 'wp_loaded' ), '4.1.0' ); + + return false; + } } $_wp_theme_features[ $feature ] = $args; @@ -1763,6 +1772,14 @@ function current_theme_supports( $feature ) { if ( !isset( $_wp_theme_features[$feature] ) ) return false; + if ( 'title-tag' == $feature ) { + // Don't confirm support unless called internally. + $trace = debug_backtrace(); + if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) { + return false; + } + } + // If no args passed then no extra checks need be performed if ( func_num_args() <= 1 ) return true; diff --git a/wp-includes/version.php b/wp-includes/version.php index ef26277c45..25bc96db58 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30073'; +$wp_version = '4.1-alpha-30074'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.