[wp-trac] [WordPress Trac] #59252: is_front_page returns false when a static blog page has been set.

WordPress Trac noreply at wordpress.org
Thu Aug 31 07:51:12 UTC 2023


#59252: is_front_page returns false when a static blog page has been set.
--------------------------+-----------------------------
 Reporter:  neo2k23       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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

 [[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
 <?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

 [[Image(https://share.getcloudapp.com/lluXB459)]]


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

 {{{#!php
 <?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();

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59252>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list