Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 3 down vote accepted

Try it:

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

Or this:

<?php
body_class( ! is_home() ? "interior" : "" );
?>
share|improve this answer
    
Thanks for your answer! however it still adds interior to the 'home' page as well. –  BeEasy Feb 13 '13 at 19:52
    
Oddly, worked here. –  Thiago Locks Feb 13 '13 at 20:03
1  
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. –  BeEasy 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

 
discard

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.