if ( is_home() && ! is_front_page() )

I see the following code a lot in index.php files. I understand that is_front_page() returns true when viewing the Site Front Page (whether displaying the blog posts index or a static page), while is_home() returns true when viewing the Blog Posts Index (whether displayed on the front page or on a static page). I am still somewhat stumped about the use of the following code –

<?php if ( have_posts() ) : ?>

    <?php if ( is_home() && ! is_front_page() ) : ?>
            <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    <?php endif; ?>

Any explanation of why this piece of code is so popular is greatly appreciated.


This will display the title of the page when a static page is set to show posts.


I show posts on my homepage…
It’ll do nothing.

If I, say, show posts on page titled News
It’ll show News in H1.

This is used so that the title of the page is shown, whenever posts are shown on a page, but nothing when blog posts are shown on the front page (home page).

We do it because if it’s on home page… it will show the title of the first post, making it appear twice (once at the top in H1 and again when posts are looped through).

Leave a Comment