is_home()WP 1.5.0

Checks whether the page showing posts is being displayed, usually this is the site's front page. Conditional tag.

This tag is very similar to is_front_page().

The behavior of this tag depends on the settings of the parameter:

  • Settings > Reading > Your homepage displays.

By default, the site's latest posts are displayed on the front page and this tag will work for that page. But if you change the settings and specify specific pages for the front page and for posts page, then this tag will work for the posts page and will stop working for the site's front page.

On paginated pages this tag will also trigger: /page/2.

1 time — 0.00005 sec (very fast) | 50000 times — 0.02 sec (speed of light)

No Hooks.

Returns

true|false. Whether the query is for the blog homepage.

Usage

if( is_home() ){
   // code
}

Examples

0

#1 Displaying different content for the home page and others pages

For example, we want to display something in the sidebar for the main page and something other for the others pages:

if( is_home() ){
	echo 'Hello from the home (main) page.';
}
else {
	echo 'Hello from internal page.';
}
0

#2 Settings of "main page" and "posts page»

Options where page IDs are stored, which are set for the "home page" and "posts page":

// The ID of the static page that is listed as the main page of the site
get_option( 'page_on_front' );

// The ID of the static page that is listed as blog page (the latest posts of the site)
get_option( 'page_for_posts' );

Notes

Changelog

Since 1.5.0 Introduced.

is_home() code WP 6.9

function is_home() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
		return false;
	}

	return $wp_query->is_home();
}