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()
?
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: