Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#37409 new defect (bug)

Broken & illogic conditional check in wp_get_document_title()

Reported by: renehermi's profile ReneHermi Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.3
Component: General Keywords:
Focuses: Cc:

Description

        /*
         * 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_singular() ) {
        $title = the_title_attribute('echo=0');


should be changed to:

        /*
         * 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_singular() ) {
        $title = the_title_attribute('echo=0');


For now it does not lead to wrong title because the previous condition is_front_page() is catching this before it throws out a wrong title but it should be fixed before it leads to issues when someone decided to do some changes on wp_get_document_title().

You can reproduce a possible error with commenting the condition is_front_page() in wp_get_document_title(). Than visit a frontpage with multiple blog posts. You will see that the wp_get_document_title() will return than the title of the first blog post and not the site title as expected.

Change History (3)

#1 @achbed
8 years ago

Is this check for is_home() even needed, since we should have already covered all applicable cases with the is_front_page() and is_post_type_archive() checks above that? There's no harm in leaving it in, but the optimizer in me says unit test this and remove if it causes no change. An electron saved is an electron earned :)

Last edited 8 years ago by achbed (previous) (diff)

#2 @ReneHermi
8 years ago

:+1 Removing is_home() completely was also my first thought but without unit testing it i was not able to track down the complete route and possible side effects.

#3 @ReneHermi
8 years ago

More testing indicated that is_home() must be removed completely if we consider to clean it up.
My initial suggestion leads to conditional fault when mashsb_get_document_title() is used on any other page other than is_home().

During my testing removing is_home() condition works flawless on all included conditions.

Note: See TracTickets for help on using tickets.