Add body class to WordPress posts without featured image

You might need to apply different styling to posts without a featured image, this function will add a class to the body tag to all single posts without a featured image:

/**
*
* Add body class to posts without featured image
*
*/

function add_body_class_no_featured_image( $classes ) {
  if(is_single() && !has_post_thumbnail()) {
    $classes[] = 'no-featured-image';
  }
  return $classes;
}
add_filter( 'body_class','add_body_class_no_featured_image' );

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>