From bbe6aa01aaa1b0a31d4e16841210916616642eb7 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 19 Nov 2015 17:08:33 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@35706 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 40 +++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index beae029b13..f554e1fdc5 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -847,10 +847,27 @@ function wp_get_document_title() { 'title' => '', ); + // If it's a 404 page, use a "Page not found" title. + if ( is_404() ) { + $title['title'] = __( 'Page not found' ); + + // If it's a search, use a dynamic search results title. + } elseif ( is_search() ) { + /* 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. - if ( is_home() && is_front_page() ) { + } elseif ( is_home() && is_front_page() ) { $title['title'] = get_bloginfo( 'name', 'display' ); + // If on a post type archive, use the post type archive title. + } elseif ( is_post_type_archive() ) { + $title['title'] = post_type_archive_title( '', false ); + + // If on a taxonomy archive, use the term title. + } elseif ( is_tax() ) { + $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. @@ -862,22 +879,13 @@ function wp_get_document_title() { } elseif ( is_singular() ) { $title['title'] = single_post_title( '', false ); - // If on a category or tag or taxonomy archive, use the archive title. - } elseif ( is_category() || is_tag() || is_tax() ) { + // If on a category or tag archive, use the term title. + } elseif ( is_category() || is_tag() ) { $title['title'] = single_term_title( '', false ); - // If it's a search, use a dynamic search results title. - } elseif ( is_search() ) { - /* translators: %s: search phrase */ - $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); - // If on an author archive, use the author's display name. - } elseif ( is_author() ) { - $title['title'] = get_the_author(); - - // If on a post type archive, use the post type archive title. - } elseif ( is_post_type_archive() ) { - $title['title'] = post_type_archive_title( '', false ); + } elseif ( is_author() && $author = get_queried_object() ) { + $title['title'] = $author->display_name; // If it's a date archive, use the date as the title. } elseif ( is_year() ) { @@ -888,10 +896,6 @@ function wp_get_document_title() { } elseif ( is_day() ) { $title['title'] = get_the_date(); - - // If it's a 404 page, use a "Page not found" title. - } elseif ( is_404() ) { - $title['title'] = __( 'Page not found' ); } // Add a page number if necessary.