0

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 to all interior pages except the 'home page'?

3

2 Answers 2

6

http://codex.wordpress.org/Function_Reference/is_home

<?php if (!is_home()) body_class('interior'); ?>

Unless you mean http://codex.wordpress.org/Function_Reference/is_front_page

<?php if (!is_front_page()) body_class('interior'); ?>
2
  • Can this be another way of writing it? ` <?php body_class( ! is_home() ? "interior" : "" ); ?>`
    – breezy
    Commented Feb 13, 2013 at 20:05
  • @BeEasy if it works and you prefer it there's no harm in using that syntax.
    – Popnoodles
    Commented Feb 13, 2013 at 21:27
0

I think the best solution is write:

<body <?php if (!is_front_page()) body_class('interior'); ?> <?php body_class(); ?>>

In this way you add only class="interior" in all page except the front page, and you can save the class in the front page, otherwise in you use only the fist php code in the tag <body> in home you will not have class.

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