WordPress.org

Make WordPress Core

Ticket #34962: 34962.3.diff

File 34962.3.diff, 4.0 KB (added by peterwilsoncc, 5 years ago)
  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 5b9049b..151daf8 100644
    a b function wp_get_document_title() { 
    856856                /* translators: %s: search phrase */
    857857                $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
    858858
    859         // If on the home or front page, use the site title.
    860         } elseif ( is_home() && is_front_page() ) {
     859        // If on the front page, use the site title.
     860        } elseif ( is_front_page() ) {
    861861                $title['title'] = get_bloginfo( 'name', 'display' );
    862862
    863863        // If on a post type archive, use the post type archive title.
    function wp_get_document_title() { 
    869869                $title['title'] = single_term_title( '', false );
    870870
    871871        /*
    872          * If we're on the blog page and that page is not the homepage or a single
    873          * page that is designated as the homepage, use the container page's title.
     872         * If we're on the blog page that is not the homepage or
     873         * a single post of any post type, use the post title.
    874874         */
    875         } elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) {
    876                 $title['title'] = single_post_title( '', false );
    877 
    878         // If on a single post of any post type, use the post title.
    879         } elseif ( is_singular() ) {
     875        } elseif ( is_home() || is_singular() ) {
    880876                $title['title'] = single_post_title( '', false );
    881877
    882878        // If on a category or tag archive, use the term title.
    function wp_get_document_title() { 
    904900        }
    905901
    906902        // Append the description or site title to give context.
    907         if ( is_home() && is_front_page() ) {
     903        if ( is_front_page() ) {
    908904                $title['tagline'] = get_bloginfo( 'description', 'display' );
    909905        } else {
    910906                $title['site'] = get_bloginfo( 'name', 'display' );
  • tests/phpunit/tests/general/document-title.php

    diff --git a/tests/phpunit/tests/general/document-title.php b/tests/phpunit/tests/general/document-title.php
    index 19886a5..e645ce1 100644
    a b class Tests_General_DocumentTitle extends WP_UnitTestCase { 
    7979
    8080        function test_front_page_title() {
    8181                update_option( 'show_on_front', 'page' );
    82                 update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
    8382                update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
     83                add_filter( 'document_title_parts', array( $this, '_front_page_title_parts' ) );
    8484
    8585                $this->go_to( '/' );
    86 
    87                 $this->assertEquals( sprintf( 'front-page – %s', $this->blog_name ), wp_get_document_title() );
     86                $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    8887
    8988                update_option( 'show_on_front', 'posts' );
    90         }
    9189
    92         function test_home_title() {
    9390                $this->go_to( '/' );
    94 
    95                 add_filter( 'document_title_parts', array( $this, '_home_title_parts' ) );
    96 
    9791                $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    9892        }
    9993
    100         function _home_title_parts( $parts ) {
     94        function _front_page_title_parts( $parts ) {
    10195                $this->assertArrayHasKey( 'title', $parts );
    10296                $this->assertArrayHasKey( 'tagline', $parts );
    10397                $this->assertArrayNotHasKey( 'site', $parts );
    class Tests_General_DocumentTitle extends WP_UnitTestCase { 
    10599                return $parts;
    106100        }
    107101
     102        function test_home_title() {
     103                $blog_page_id = $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) );
     104                update_option( 'show_on_front', 'page' );
     105                update_option( 'page_for_posts', $blog_page_id );
     106
     107                // Show page name on home page if it's not the front page.
     108                $this->go_to( get_permalink( $blog_page_id ) );
     109                $this->assertEquals( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
     110
     111                update_option( 'show_on_front', 'posts' );
     112        }
     113
    108114        function test_paged_title() {
    109115                $this->go_to( '?page=4' );
    110116