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.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE
magnifiercross
>
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: