How to output placeholder image if no featured image set?

I think that you’re adding the code inside the loop of index.php or blog template file. You might be try this kind of things:

if ( class_exists( 'MultiPostThumbnails' ) && 
     ( MultiPostThumbnails::has_post_thumbnail( get_post_type(), 'header-image' , get_the_ID() ) ) ) { 
       MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'header-image', NULL, 
                          'header-image-full', 
                           array('class' => "custom-header-image") ); 

} else {  
  $image = get_template_directory_uri() .'/assets/img/placeholders/placeholder.png'; 
  echo '<img src="'.$image.'" alt="" />';
}

Leave a Comment