Last Updated: February 25, 2016
· johncionci

WordPress (NO) Post Thumbnail fix

Using WordPress we obviously do alot of "blog" oriented layouts. More often than not these "rivers" have a post thumbnail, title, post meta, and an excerpt.


So the post thumbnail is typically floated left, with all the other post information margin(ed)-left for a clean non-wrapping appearance.

The problem is, "What happens when there is no post thumbnail associated with the post?"

We end up with a blank whitespace, not fun!


The solution for me was to hook on the WordPress's post_class(). By adding this quick snippet we can check to see if the current post has, or does not have a post thumbnail associated with it, add a new "no-thumbnail" class, and therefore be able to style those particular posts differently.

function my_has_thumbnail_class( $classes ) {
global $post;
if( !has_post_thumbnail() )
    $classes[] = 'no-thumbnail';
return $classes;
add_filter( 'post_class', 'my_has_thumbnail_class' );

Giving us a clean consistent layout.