Make WordPress Core

Opened 13 months ago

Last modified 11 months ago

#59252 reopened defect (bug)

is_front_page returns false when a static blog page has been set.

Reported by: neo2k23's profile neo2k23 Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: General Keywords:
Focuses: Cc:

Description

Hi

I have a question. I do not know if this is a bug or not, but the behaviour of the is_front_page() function is bit ackward.

If no static homepage has been set and you call on the home page the function is_front_page() it returns true. If you call is_home() it also retruns true.

However the moment you set a static blog page (not home page) that same call for is_front_page on the home page returns false, but is_home() still returns true.

Is this a bug? It does not seem consistent to me as there is no static home page set why does is_front_page() return true when no static blog page has been set and return false the moment a static blog page is set.

What has the static blog page set in the reading settings to do with the is_front_page() function?

Can somebody please explain this to me as it does not make sense given the description of is_front_page() function?

Thank you

see image

https://share.getcloudapp.com/4guXkxZy

STEPS TO CREATE THE SAME RESULTS**

Tested with wp 6.4 latest trunk build clean wordpress. 20-21 theme and php 8.0.x

just add this code to the index.php

<?php 
if ( is_home() ) echo '---------------> this is home.';
if ( is_front_page() ) echo '---------------> this is frontpage.';
?>

see image below where i added the php code

https://share.getcloudapp.com/lluXB459

The complete altered index.php of the 20-21 theme below

<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WordPress
 * @subpackage Twenty_Twenty_One
 * @since Twenty Twenty-One 1.0
 */

get_header(); ?>

<?php if ( is_home() && ! is_front_page() && ! empty( single_post_title( '', false ) ) ) : ?>
        <header class="page-header alignwide">
                <h1 class="page-title"><?php single_post_title(); echo 'HELLO fucking WORLD'; ?></h1>
        </header><!-- .page-header -->
<?php endif; ?>
<?php 
if ( is_home() ) echo '---------------> this is home.';
if ( is_front_page() ) echo '---------------> this is frontpage.';
?>

<?php
if ( have_posts() ) {

        // Load posts loop.
        while ( have_posts() ) {
                the_post();

                get_template_part( 'template-parts/content/content', get_theme_mod( 'display_excerpt_or_full_post', 'excerpt' ) );
        }

        // Previous/next page navigation.
        twenty_twenty_one_the_posts_navigation();

} else {

        // If no content, include the "No posts found" template.
        get_template_part( 'template-parts/content/content-none' );

}

get_footer();

Change History (5)

#1 follow-up: @Marcio Zebedeu
13 months ago

I think that a post page should not be defined without first defining which page will be the home page.

However, i believe that we should keep the "post page" option active only when the "home page" is chosen.

#2 in reply to: ↑ 1 @neo2k23
13 months ago

Replying to Marcio Zebedeu:

I think that a post page should not be defined without first defining which page will be the home page.

However, i believe that we should keep the "post page" option active only when the "home page" is chosen.

Why should i define a static home page if i want to use the none static one? Does not make sense. In that case one should not be able to set a static blog page if no static home page has been set. But there is no restriction to that. If i don't have a static homepage i still can define a static blog page.

However in both cases is_home() returns true (which is correct as there is no static homepage set) but is_front_page() does only in once case (only when no static homepage and no static blog page has been set). To me this looks like a inconsistancy.

is_front_page() should only return true when a static homepage is set or in both cases when the static and non static homepage is set. But that would make is_home() redundant.

But looking at the documentation is_front_page() should only return true on the static_home_page.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


11 months ago

#4 @jorbin
11 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version changed from trunk to 2.5

is_front_page and is_home date back to 2.5 and 1.5 respectfully, so I'm adjust the version to match that.

#3682 is the ticket where is_front_page was added. ( [6704] and [6740] are the commits to add is_front_page)

While I understand the confusion here, there is extensive documentation on both https://developer.wordpress.org/reference/functions/is_front_page/ and https://developer.wordpress.org/reference/functions/is_home/ therefore I'm closing this as invalid.

#5 @neo2k23
11 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

@jorbin my question was about.

I asked why the moment you set a static blog page (not home page) that same call for is_front_page on the home page returns false.

This is not what is in the documentation.https://developer.wordpress.org/reference/functions/is_home/

In the documentation it says "On the site front page, is_front_page() will always return true, regardless of whether the site front page displays the blog posts index or a static page."

It does not!

Note: See TracTickets for help on using tickets.