Tip: is_home() vs is_front_page()

As great and simple as WordPress is, sometimes the simplest functions can be the most frustrating. is_home() and is_front_page() are two such functions that seem to be a stumbling block for some. They are extremely similar, but have major differences.

The Stumbling Block

Settings -> Reading -> Front Page
Settings -> Reading -> Front Page

Both is_home and is_front_page are WordPress conditionals that can be used to display (or not display) elements on the home page of your website. There’s a slight difference in that is_front_page will return true if the user is on the page that is set to the Front Page in Settings->Reading->Front page, as well as the page of posts. Where as is_home will return true on the posts index page, whether or not it’s the website’s home page or not.

I think that’s where the confusion is. WordPress is a blogging platform at heart and therefore the Home Page is normally the Blog Index, so the conditional makes sense semantically. But as we use WordPress as a CMS, designs call for a static page to be used as a the Home Page, putting the Blog Index elsewhere on the site. Which now puts is_home semantically out of whack.

Why use is_front_page()? Why use is_home()?

A few years ago, I ran into this exact scenario where I learned the differences between the two. The redesign called for a static homepage but then a separate blog page. There was a specific 3 item navigation that was only to be displayed on the website’s Home Page and for whatever reason it wasn’t displaying on the Home Page, but rather on the Blog Page (Blog Index). In reading the codex on is_home, I realized that I wasn’t using the proper conditional for this scenario. In the previous projects, this method worked only because the Blog Index was the Home Page of the website. I got lucky in that it worked. But in learning the differences because of re-design project, I went back to the two previous projects and placed in the proper ones.

/ Jason Resnick

Jason is a WordPress developer helping small businesses, design and marketing agencies achieve their goals by specializing in Ecommerce and increasing conversions. Learn more about him here.

More Posts | Twitter | Work ON Your Business Challenge | Coaching

One response to “Tip: is_home() vs is_front_page()

  1. Youre quite right, it is confusing:

    “Both is_home and is_front_page are WordPress conditionals that can be used to display (or not display) elements on the home page of your website.…There‚Äôs a slight difference in that is_front_page will return true if the user is on the page that is set to the Front Page in Settings->Reading->Front page, as well as the page of posts.

    The latter makes no sence but is correct. Its really hard to straighten this thing out.

    Your “scenario” is also so true, and typically when administrors delivers “mostly CMS” and are not active bloggers ourselfs. I took me 8 years before I selected “Front page displays: Your latest posts”. This is the summary I learned by thinking “Backwards”:

    Please correct me if im wrong.

    WordPress is old
    And the vocabulary is from the time “pages” did not exists. The “Front page displays” is a relic from the past, and so is the condition is_home().

    These are the same thing:
    Post page: -select-
    “Your latest posts”
    Blog index page

    WordPress should cleanup this. is_home() refers to all of these three vocabularies, and the whole bunch shold be something like is_blog_root().

    is_home() is not the “same as” your website landing / startpage
    is_home() is not telling you that you are viewing your website landing / startpage
    is_home() is not true because you are currently using templatefile index.php
    is_home() true statement might not even exists, and is likly never true on your site.

    So, What do we know? When is_home() absolute true?
    is_home() is always true if WordPress are currently using templatefile home.php.

    If home.php doesnt exists, the top level fallback template file index.php is in use. Thats why is_home() Might be true when WordPress using index.php template file.

    So, When is home.php in use?
    Lets say you have 5 Categories on the same top level, and you wanna list all posts, mixed from all categories in one place. You need a Blog index page.
    Lets say you have No categories att all. You need to present a list of your posts somewhere. You need a Blog index page.

    So, What is a Blog index page?
    Blog index page is what you choose in settings->”Front page displays: A static page (select below) ” and “Post page: -select-“. (and select a page)

    So, How do I access my Blog index page?
    a)Put the selected page in a menu -as you would for any other created page.

    So, How do I style and take control of my Blog index page?
    The selected page is just a placeholder, and uses the Title only. The template is_page() is never called, instead home.php (! ) is in use. And to add conditional content, use if(is_home())) …

    So, How do I access my Blog index page?
    b)Choose to use this page as “Front page” – your website landing / startpage, by click on the top radio input choice “Your latest posts “.
    Now your current Blog index page also respond: is_front_page() = true and is_home() = true

    “Your latest posts “is a built in Blog index “page”, a setting without a placeholder page is selected below. Then, for example, the only way to access the title is to edit the templatefile home.php or filter the_title within functions.php with if(is_home())…

    So, How do I access my Blog index page? (Not recommended)
    c)Choose “Front page displays: A static page (select below) ” and “Post page: -select-” (and select a page) and make shure “Front page: -select-” has NO SELECTED page. This works but some query conditionals are messed up.

    This is the confusing part
    Today, This setting to choose a Blog index page has nothing to with “Front page display”. Post page setting should be on General. When Choosing a “Frontpage”, there is only need for one dropdown selector. “Choose page”. If the page you selected is “the Blog index page”, well, thats the same as “Your latest posts”…

    The Codex says diffrent query methods are in use for is_front_page() vs is_home(), but I dont understand why the GUI have to reflect this at the backend.

    Please correct my conclusions if Im wrong

    / Thanks

Leave a Comment

Your email address will not be published. Required fields are marked *