WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is home

Description

This Conditional Tag checks if the blog posts index page is being displayed. This is a Boolean function, meaning it returns either TRUE or FALSE.

Usage

<?php is_home(); ?>

Parameters

This tag does not accept any parameters.

Return Values

(boolean) 
True on success, false on failure.

Blog Posts Index vs. Site Front Page

Since WordPress 2.1, when the static front page functionality was introduced, the blog posts index and site front page have been treated as two different query contexts, with is_home() applying to the blog posts index, and is_front_page() applying to the site front page.

Be careful not to confuse the two query conditionals:

  • On the site front page, is_front_page() will always return TRUE, regardless of whether the site front page displays the blog posts index or a static page.
  • On the blog posts index, is_home() will always return TRUE, regardless of whether the blog posts index is displayed on the site front page or a separate page.

Whether is_home() or is_front_page() return TRUE or FALSE depends on the values of certain option values:

  • get_option( 'show_on_front' ): returns either 'posts' or 'page'
  • get_option( 'page_on_front' ): returns the ID of the static page assigned to the front page
  • get_option( 'page_for_posts' ): returns the ID of the static page assigned to the blog posts index (posts page)

When using these query conditionals:

  • If 'posts' == get_option( 'show_on_front' ):
    • On the site front page:
      • is_front_page() will return TRUE
      • is_home() will return TRUE
    • If assigned, WordPress ignores the pages assigned to display the site front page or the blog posts index
  • If 'page' == get_option( 'show_on_front' ):
    • On the page assigned to display the site front page:
      • is_front_page() will return TRUE
      • is_home() will return FALSE
    • On the page assigned to display the blog posts index:
      • is_front_page() will return FALSE
      • is_home() will return TRUE

Examples

The following example can be used in your sidebar to display different content when displaying the blog posts index.
<?php
if ( is_home() ) {
    
// This is the blog posts index
    
get_sidebar'blog' );
} else {
    
// This is not the blog posts index
    
get_sidebar();
}
?>

Notes

is_home uses the global $wp_query WP_Query object. is_home isn't usable before the parse_query action.

Obsolete Usage

Prior to WordPress 2.1, WordPress did not have static front page functionality, which meant that the site front page and the blog posts index were always the same. Thus, is_home() always returned TRUE on the site front page.

Change Log

Since: 1.5.0

Source File

is_home() is located in wp-includes/query.php.

Related

See also index of Function Reference and index of Template Tags.