I have 2 categories, just to make an easy example, Cars and Bikes. I have a post that fits both of the category. If i visit the Cars category, the body_class looks like this:

"archive category category-cars category-1 category-cars category-bikes"

The problem is that somehow the post category is visible in the body_class after the category-1 classname. How can i avoid this? I need to use different colors for different categories, but right now the category-bikes class overwrites the category-cars class.


1 Answer 1


This could be solved via CSS as well. Just set up declarations for the special cases where there is overlap between categories:

.category-cars { background-color: #f00; }
.category-cars.category-bikes { background-color: #0f0; }

This will give any posts that are in both bikes and cars the same background color as those used in the bikes category.

  • Yes, but i have 9 categories, so this solution is not exactly what i am looking for. But thanks:) Maybe i just remove the body_class function and add the category slug to the body...
    – passatgt
    Jul 25, 2012 at 15:32
  • I just duplicated the get_body_class function to my functions.php, and if i change return apply_filters( 'body_class', $classes, $class ); to return $classes, it works fine. I guess something is using a filter to hook up those extra category classes, but i can't find it anywhere...
    – passatgt
    Jul 25, 2012 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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