In Oxygen’s Facebook group a user asks:
Does anyone know how to set a fallback image on a post?
This is if a client forgets to set a featured image.
Thank you.
Assuming that this is about the output of featured images by the Easy Posts component, here’s how we can set a fallback image in case there is no featured image for a post.
Step 1
Upload your desired fallback image to the Media Library.
Step 2
Edit Template PHP of the Easy Posts component.
Replace
<a class='oxy-post-image' href='<?php the_permalink(); ?>'>
<div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo get_the_post_thumbnail_url(); ?>);'>
with
<?php
if ( has_post_thumbnail() ) {
$image = get_the_post_thumbnail_url();
} else {
$image = 'https://example.com/wp-content/uploads/2019/05/fallback.jpg';
}
?>
<a class='oxy-post-image' href='<?php the_permalink(); ?>'>
<div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo $image; ?>);'>
Replace https://example.com/wp-content/uploads/2019/05/fallback.jpg
in the above with the URL of your fallback image.