WordPress4.1 wp_title()関数の変更点

version4.1では、wp_title() 関数の変更があります。

テーマでは、現在 add_theme_support() でサポート可能な機能が以下のようになっていますが

  • post-formats
  • post-thumbnails
  • custom-background
  • custom-header
  • automatic-feed-links
  • menus
  • html5

これに、title-tag が追加されます。

テーマがこの機能をサポートすると

add_theme_support( 'title-tag' );
	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 ) );
		}
	}

サイト名、サイト概要(トップページのみ)、ページ数がタイトルに追加されます。

多くのテーマは、wp_title hookを使って、付随する情報をタイトルに追加していると思いますが、今後、add_theme_support( ‘title-tag’ ); で OK ってことになるかも

関連する関数
general-template.php

/**
 * Display title tag with contents.
 *
 * @since 4.1.0
 * @access private
 * @internal
 *
 * @see wp_title()
 */
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";
}

[emulsion_relate_posts]