[wp-trac] [WordPress Trac] #34962: Issues with wp_get_document_title function in wp-includes/general-template.php causing problems with document titles
WordPress Trac
noreply at wordpress.org
Thu Dec 10 00:56:03 UTC 2015
#34962: Issues with wp_get_document_title function in wp-includes/general-
template.php causing problems with document titles
----------------------------+-----------------------------
Reporter: kasia_codeword | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.4
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
Please see this thread on the support forum as a primer:
https://wordpress.org/support/topic/document-titles-in-44
Document titles for site front pages are not being generated correctly if
Front page and Posts page are set to static pages in Reading Settings.
From what I can tell, the issue is related to three sections of code in
wp-includes/general-template.php
First, lines 859-861
{{{
// If on the home or front page, use the site title.
} elseif ( is_home() && is_front_page() ) {
$title['title'] = get_bloginfo( 'name', 'display' );
}}}
This is actually saying that if is_home and is_front_page both return
true, then use the site title, however the only way that both is_home and
is_front_page can return true is if Front page is set to "your latest
posts" in Reading Settings. Therefore, if a static page is selected as the
front page in Reading Settings, the site title will not be used.
Then, lines 871-876
{{{
/*
* 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.
*/
} elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() &&
is_front_page() ) ) {
$title['title'] = single_post_title( '', false );
}}}
This is saying that if it is the blog index but the blog index is not the
home page of the site, OR if it is the front page of the site but the
front page is not the blog index (in other words, a static page is the
front page) then use the single post title.
So up to this point if I have a static page called Home set as my front
page, what returns as the document title is Home - Site Title rather than
Site Title - Tagline.
Finally, lines 906-911
{{{
// Append the description or site title to give context.
if ( is_home() && is_front_page() ) {
$title['tagline'] = get_bloginfo( 'description', 'display'
);
} else {
$title['site'] = get_bloginfo( 'name', 'display' );
}
}}}
This is saying to append the tag line only if is_home and is_front_page
both return true, otherwise append the site title. The only way both can
return true is if "Front page displays" in Reading Settings is always set
to "your latest posts".
So basically all of this means that anyone with a site configuration where
the front page and posts page are set to static pages cannot use the Site
Title - Tagline configuration for the document title on the front page of
the site.
I fiddled around a bit with the code, I'm not sure that this is entirely
correct in terms of best practice but I was able to get things to behave
as they used to in this regard in 4.3.1 by making the following changes:
Lines 859-861
{{{
// If on the home or front page, use the site title.
} elseif ( is_front_page() ) {
$title['title'] = get_bloginfo( 'name', 'display' );
}}}
using the logic that regardless of whether Front Page is set to "your
latest posts" or a static page in Reading settings, is_front_page will
return as true in both cases.
Lines 875-876
{{{
} elseif ( is_home() && ! is_front_page() ) {
$title['title'] = single_post_title( '', false );
}}}
using the logic that we would only want to use the single post title if it
is a blog post archive that is not the front page where is_home returns
true but is_front_page returns false.
Lines 906-911
{{{
// Append the description or site title to give context.
if ( is_front_page() ) {
$title['tagline'] = get_bloginfo( 'description', 'display'
);
} else {
$title['site'] = get_bloginfo( 'name', 'display' );
}
}}}
again using the logic that is_front_page returns true regardless of
whether "latest posts" or static page is selected as the front page.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34962>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list