WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a class to the body tag to all pages EXCEPT the homepage. Right now I have.

<?php body_class('interior'); ?>

But it adds 'interior' to ALL pages including the home page.

What is the best standard way of adding a class to the body tag?

share|improve this question
up vote 3 down vote accepted

Try it:

$class = ! is_home() ? "interior" : "";
body_class( $class );

Or this:

body_class( ! is_home() ? "interior" : "" );
share|improve this answer
Thanks for your answer! however it still adds interior to the 'home' page as well. – Bryan Barrera Feb 13 '13 at 19:52
Oddly, worked here. – Thiago Locks Feb 13 '13 at 20:03
Try it: <body <?php body_class( ! is_home() && ! is_front_page() ? "interior" : "" ); ?>> – Thiago Locks Feb 13 '13 at 20:04
I adjusted my reading settings to static and have no pages selected & it worked. – Bryan Barrera Feb 13 '13 at 20:06

The filter body_class can be used for this.

add_filter( 'body_class', 'body_class_wpse_85793', 10, 2 );

function body_class_wpse_85793( $classes, $class )
    // This one overrides all original classes
    if( is_home() )
        $classes = array( 'interior' );

    // This one simply adds a new class
    //if( is_home() )
    //  $classes[] = 'interior';

    return $classes;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.