1

I have set my front page set to be a static front page, "Home," and my Posts page is set to my "News" page.

When on my News page, is_home() returns 1 as expected but is_archive() returns 0. I would expect that it would return 1 also. The WP doc for is_archive() doesn't make it clearer for me. It reads,

checks if any type of Archive page is being displayed. An Archive is a Category, Tag, Author or a Date based pages.

I would expect that to be true. Something isn't connecting for me.

What is the difference between is_home() and is_archive()?

  • Thank you for bringing this to my attention. I forgot to come back here after I got it working. I'll close it now. – Jeff Jan 13 '15 at 19:20
  • No problem. Enjoy :-) – Pieter Goosen Jan 13 '15 at 19:26
3

To properly understand the difference, you have to dig into the Wordpress Core

  • is_archive() (defined in wp-includes/query.php#L140) checks any type of archive page. These archive pages is defined in the WP_Query class in wp-includes/query.php#L1615 lines 1615 and line 1616

    1615    if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
    1616    $this->is_archive = true;
    
  • is_home()(defined in wp-includes/query.php#L443) will return true when you are on the home page, which is whenever any of the conditions/pages returns false as defined in the WP_Query class in wp-includes/query.php#L1648 lines 1648 and 1649

    1648    if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup || $this->is_robots ) )
    1649    $this->is_home = true;
    

As for your question, whenever a static front page is set, Wordpress uses front-page.php, page.php or any other custom page template. The proper conditional to use here is is_front_page()

For the page set as the blog page, Wordpress uses home.php or index.php. This is your actual homepage of your blog, and not an archive page. is_home() will return true and is_archive() will return false as expected

For futher reading:

2

if you have home.php/index.php on your theme it's your first page and function is_home() return true in this page.

but when you are on archive.php function is_archive() will return true. archive.php is for displaying posts of a year or a month or a day. you can test archive functionality with adding it's widget to your site.

1

To expand on @AmirMasoud's answer, when you're on your news feed, it is not actually displaying a category, tag, author, etc specific set of posts.

Also in your options there is a place you can define home. That page may be outside of using index.php and will be the only page that returns 1 as is_home().

Archive can be set a lot of different ways. Look up the template hierarchy to better understand home, archive and the other page file options.

  • "Archive can be set a lot of different ways" Please explain what you mean. You cannot set an archive page – Pieter Goosen Aug 14 '14 at 8:11
  • Well that is a good question... it isn't really the developer setting them that was more of a wording mistake. But there are defaults that are set. So archives are set for multiple ways. But you can set a variety of php files that all act as archives. Not just archive.php. – Cayce K Aug 14 '14 at 11:12
  • You can create the following archive pages, archive.php, category.php, taxonomy.php, tag.php, author.php and date.php and any of their hierarchial pages according to the template hierarchy ;-) – Pieter Goosen Aug 14 '14 at 11:26
  • Exactly! :D Your answer is much more in depth. I wanted to go a little bit more, but was on my phone so I'm very glad you were able to do that! – Cayce K Aug 14 '14 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.