WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 am using body_class(); to style different sections of a wordpress site by their body class. Page styles descend from .page-template, blog styles descend from .single-post and/or .blog etc.

I have created a custom post type "Products" for the products section of the site and want to style this section specifically using it's body class, but unfortunately body_class(); is also giving the custom post type single pages the class .blog which is making many of the blog styles override the product styles- very frustrating.

Is there a way to take the "blog" class away for my custom post type single pages?


share|improve this question
up vote 3 down vote accepted

You can use body_class filter to check if you are on your custom post type, and if so then just remove the blog class like this:

 function remove_blog_from_cpt_classes($classes, $class){
    global $post;
    if ($post->post_type != "products"){
        return $classes;
        foreach($classes as &$str){
            if(strpos($str, "blog") > -1){
                $str = "";
    return $classes;
add_filter("body_class", "remove_blog_from_cpt_classes", 10, 2);

Hope this helps

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.