Categories
Code

Add body class if post has a featured image in WordPress

This WordPress function adds a body class ‘has-featured-image’ if the current post has a featured image assigned.

add_action('body_class', 'ed_if_featured_image_class' );
function ed_if_featured_image_class($classes) {
 if ( has_post_thumbnail() ) {
 array_push($classes, 'has-featured-image');
 }
 return $classes;
}

One reply on “Add body class if post has a featured image in WordPress”

Comments are closed.