diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 5b9049b9fd..151daf860c 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -856,8 +856,8 @@ function wp_get_document_title() { /* translators: %s: search phrase */ $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); - // If on the home or front page, use the site title. - } elseif ( is_home() && is_front_page() ) { + // If on the front page, use the site title. + } elseif ( is_front_page() ) { $title['title'] = get_bloginfo( 'name', 'display' ); // 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 ); /* - * If we're on the blog page and that page is not the homepage or a single - * page that is designated as the homepage, use the container page's title. + * If we're on the blog page that is not the homepage or + * a single post of any post type, use the post title. */ - } elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) { - $title['title'] = single_post_title( '', false ); - - // If on a single post of any post type, use the post title. - } elseif ( is_singular() ) { + } elseif ( is_home() || is_singular() ) { $title['title'] = single_post_title( '', false ); // 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. - if ( is_home() && is_front_page() ) { + if ( is_front_page() ) { $title['tagline'] = get_bloginfo( 'description', 'display' ); } else { $title['site'] = get_bloginfo( 'name', 'display' ); diff --git a/tests/phpunit/tests/general/document-title.php b/tests/phpunit/tests/general/document-title.php index 19886a5c00..0e5d282a40 100644 --- a/tests/phpunit/tests/general/document-title.php +++ b/tests/phpunit/tests/general/document-title.php @@ -79,25 +79,19 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { function test_front_page_title() { 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' ) ) ); + add_filter( 'document_title_parts', array( $this, '_front_page_title_parts' ) ); $this->go_to( '/' ); - - $this->assertEquals( sprintf( 'front-page – %s', $this->blog_name ), wp_get_document_title() ); + $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); update_option( 'show_on_front', 'posts' ); - } - function test_home_title() { $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() ); } - function _home_title_parts( $parts ) { + function _front_page_title_parts( $parts ) { $this->assertArrayHasKey( 'title', $parts ); $this->assertArrayHasKey( 'tagline', $parts ); $this->assertArrayNotHasKey( 'site', $parts ); @@ -105,6 +99,16 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { 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() { $this->go_to( '?page=4' );