Make WordPress Core


Ignore:
Timestamp:
11/19/2015 05:08:33 PM (10 years ago)
Author:
obenland
Message:

Template: Use template-loader.php as cononical source of truth for conditional ordering.

Reverts [35700] which didn't account for author archives without posts.
Determination of the correct title is now based on the same order of
conditionals that template loader uses to select the right template.

H/t ocean90.
Fixes #34516.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r35700 r35706  
    848848    );
    849849
    850     // If on the home or front page, use the site title.
    851     if ( is_home() && is_front_page() ) {
    852         $title['title'] = get_bloginfo( 'name', 'display' );
    853 
    854     /*
    855      * If we're on the blog page and that page is not the homepage or a single
    856      * page that is designated as the homepage, use the container page's title.
    857      */
    858     } elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) {
    859         $title['title'] = single_post_title( '', false );
    860 
    861     // If on a single post of any post type, use the post title.
    862     } elseif ( is_singular() ) {
    863         $title['title'] = single_post_title( '', false );
    864 
    865     // If on a category or tag or taxonomy archive, use the archive title.
    866     } elseif ( is_category() || is_tag() || is_tax() ) {
    867         $title['title'] = single_term_title( '', false );
     850    // If it's a 404 page, use a "Page not found" title.
     851    if ( is_404() ) {
     852        $title['title'] = __( 'Page not found' );
    868853
    869854    // If it's a search, use a dynamic search results title.
     
    872857        $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
    873858
    874     // If on an author archive, use the author's display name.
    875     } elseif ( is_author() ) {
    876         $title['title'] = get_the_author();
     859    // If on the home or front page, use the site title.
     860    } elseif ( is_home() && is_front_page() ) {
     861        $title['title'] = get_bloginfo( 'name', 'display' );
    877862
    878863    // If on a post type archive, use the post type archive title.
     
    880865        $title['title'] = post_type_archive_title( '', false );
    881866
     867    // If on a taxonomy archive, use the term title.
     868    } elseif ( is_tax() ) {
     869        $title['title'] = single_term_title( '', false );
     870
     871    /*
     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.
     874     */
     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() ) {
     880        $title['title'] = single_post_title( '', false );
     881
     882    // If on a category or tag archive, use the term title.
     883    } elseif ( is_category() || is_tag() ) {
     884        $title['title'] = single_term_title( '', false );
     885
     886    // If on an author archive, use the author's display name.
     887    } elseif ( is_author() && $author = get_queried_object() ) {
     888        $title['title'] = $author->display_name;
     889
    882890    // If it's a date archive, use the date as the title.
    883891    } elseif ( is_year() ) {
     
    889897    } elseif ( is_day() ) {
    890898        $title['title'] = get_the_date();
    891 
    892     // If it's a 404 page, use a "Page not found" title.
    893     } elseif ( is_404() ) {
    894         $title['title'] = __( 'Page not found' );
    895899    }
    896900
Note: See TracChangeset for help on using the changeset viewer.