is_home()

Determines whether the query is for the blog homepage.


Description Description

The blog homepage is the page that shows the time-based blog content of the site.

is_home() is dependent on the site’s "Front page displays" Reading Settings ‘show_on_front’ and ‘page_for_posts’.

If a static page is set for the front page of the site, this function will return true only on the page you set as the "Posts page".

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

See also See also


Top ↑

Return Return

(bool) True if blog view homepage, otherwise false.


Top ↑

Source Source

File: wp-includes/query.php

481
482
483
484
485
486
487
488
489
490
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();
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

More Information More Information

Top ↑

History History

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.

Top ↑

Usage Usage

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

Top ↑

Notes Notes

is_home() uses the global $wp_query WP_Query object. is_home() isn’t usable before the ‘parse_query’ action.



Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by znowebdev

    The following example can be used in your sidebar to display different content when displaying the blog posts index.

    1
    2
    3
    4
    5
    6
    7
    if ( is_home() ) {
        // This is the blog posts index
        get_sidebar( 'blog' );
    } else {
        // This is not the blog posts index
        get_sidebar();
    }

You must log in before being able to contribute a note or feedback.