jmccole83
1/30/2018 - 10:08 AM

Fallback image using Javascript

Put an onerror event on images to load a fallback image if the original can't be found.

Below is an example featured image.

<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="" onerror="this.onerror=null;this.src='<?= get_template_directory_uri(); ?>/dist/images/example.jpg';">