Using WordPress ‘is_home()’ PHP function

The is_home() WordPress PHP function determines whether the current query is for the blog homepage.

Usage

if (is_home()) {
    // Do something if it's the blog homepage
} else {
    // Do something else if it's not the blog homepage
}

Parameters

  • None

More information

See WordPress Developer Resources: is_home()

Examples

Display Blog Sidebar on Blog Homepage

Show a different sidebar for the blog homepage and other pages.

if (is_home()) {
    get_sidebar('blog');
} else {
    get_sidebar();
}

Add a Custom Class to the Body Tag

Add a ‘blog-home’ class to the body tag on the blog homepage.

function add_custom_body_class($classes) {
    if (is_home()) {
        $classes[] = 'blog-home';
    }
    return $classes;
}
add_filter('body_class', 'add_custom_body_class');

Display a Custom Message on the Blog Homepage

Show a welcome message only on the blog homepage.

if (is_home()) {
    echo '<p>Welcome to our Blog Homepage!</p>';
}

Load a Custom CSS File on the Blog Homepage

Enqueue a custom CSS file specifically for the blog homepage.

function load_custom_css() {
    if (is_home()) {
        wp_enqueue_style('custom-css', get_template_directory_uri() . '/css/blog-home.css');
    }
}
add_action('wp_enqueue_scripts', 'load_custom_css');

Show Breadcrumbs Only on Non-Home Pages

Display breadcrumbs on all pages except the blog homepage.

if (!is_home()) {
    // Display breadcrumbs (use your theme's breadcrumb function)
}