Sep 01, 2023  

Sometimes it happens we adopt sites where no featured image where uploaded but our theme requires one in each post.
This simple PHP code allows you to automatically upload a default image (placeholder) where none is present.

<?php if ( has_post_thumbnail() ) {
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
<?php } ?>

You clearly can name your default image the way you want. You can chose for the site to display the header or an image you make and upload it where you prefer. This code has it set to be uploaded into the folder “images” of your theme, right where your header image is.

Of course if you wish your default image to have different settings than the featured one (like maybe being grey or more opacity) you can wrap the "<img src="#" alt="<?php the_title(); ?>" />" within a div and style it in css.