Template: Always display the site title on the front page.

Limits using the page title to the blog page when the site has a static front page,
bringing it N’Sync with `wp_title()`.

Props peterwilsoncc.
Fixes #34962.



git-svn-id: https://develop.svn.wordpress.org/trunk@36168 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland 2016-01-04 17:15:31 +00:00
parent f891bb32f2
commit 0d6514b28b
2 changed files with 19 additions and 19 deletions

View File

@ -856,8 +856,8 @@ function wp_get_document_title() {
/* translators: %s: search phrase */ /* translators: %s: search phrase */
$title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
// If on the home or front page, use the site title. // If on the front page, use the site title.
} elseif ( is_home() && is_front_page() ) { } elseif ( is_front_page() ) {
$title['title'] = get_bloginfo( 'name', 'display' ); $title['title'] = get_bloginfo( 'name', 'display' );
// If on a post type archive, use the post type archive title. // If on a post type archive, use the post type archive title.
@ -869,14 +869,10 @@ function wp_get_document_title() {
$title['title'] = single_term_title( '', false ); $title['title'] = single_term_title( '', false );
/* /*
* If we're on the blog page and that page is not the homepage or a single * If we're on the blog page that is not the homepage or
* page that is designated as the homepage, use the container page's title. * a single post of any post type, use the post title.
*/ */
} elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) { } elseif ( is_home() || is_singular() ) {
$title['title'] = single_post_title( '', false );
// If on a single post of any post type, use the post title.
} elseif ( is_singular() ) {
$title['title'] = single_post_title( '', false ); $title['title'] = single_post_title( '', false );
// If on a category or tag archive, use the term title. // If on a category or tag archive, use the term title.
@ -904,7 +900,7 @@ function wp_get_document_title() {
} }
// Append the description or site title to give context. // Append the description or site title to give context.
if ( is_home() && is_front_page() ) { if ( is_front_page() ) {
$title['tagline'] = get_bloginfo( 'description', 'display' ); $title['tagline'] = get_bloginfo( 'description', 'display' );
} else { } else {
$title['site'] = get_bloginfo( 'name', 'display' ); $title['site'] = get_bloginfo( 'name', 'display' );

View File

@ -79,25 +79,19 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase {
function test_front_page_title() { function test_front_page_title() {
update_option( 'show_on_front', 'page' ); update_option( 'show_on_front', 'page' );
update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) ); update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
add_filter( 'document_title_parts', array( $this, '_front_page_title_parts' ) );
$this->go_to( '/' ); $this->go_to( '/' );
$this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
$this->assertEquals( sprintf( 'front-page – %s', $this->blog_name ), wp_get_document_title() );
update_option( 'show_on_front', 'posts' ); update_option( 'show_on_front', 'posts' );
}
function test_home_title() {
$this->go_to( '/' ); $this->go_to( '/' );
add_filter( 'document_title_parts', array( $this, '_home_title_parts' ) );
$this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
} }
function _home_title_parts( $parts ) { function _front_page_title_parts( $parts ) {
$this->assertArrayHasKey( 'title', $parts ); $this->assertArrayHasKey( 'title', $parts );
$this->assertArrayHasKey( 'tagline', $parts ); $this->assertArrayHasKey( 'tagline', $parts );
$this->assertArrayNotHasKey( 'site', $parts ); $this->assertArrayNotHasKey( 'site', $parts );
@ -105,6 +99,16 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase {
return $parts; return $parts;
} }
function test_home_title() {
$blog_page_id = $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) );
update_option( 'show_on_front', 'page' );
update_option( 'page_for_posts', $blog_page_id );
// Show page name on home page if it's not the front page.
$this->go_to( get_permalink( $blog_page_id ) );
$this->assertEquals( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
}
function test_paged_title() { function test_paged_title() {
$this->go_to( '?page=4' ); $this->go_to( '?page=4' );