Adding placeholder image for posts without featured image

Can I add code to show a placeholder image if there is no featured image for a post?

If you want a plugin, I’ve heard the Default Featured Image is a good option: https://wordpress.org/plugins/default-featured-image/

Personally, I prefer do small things like this in the FUNCTIONS file. If you have basic coding skills, you’ll know what to do with this.

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

Hi Tasha,

Thanks for reaching out.
If you are using the default blog page, you need to add some custom PHP coding to show the placeholder image. Please remember that custom coding is beyond the scope of Theme Support, I would suggest you hire a developer who can assist you to do the customization or you can avail of our newly launched service called One, where we answer the questions beyond normal theme support.

And, If you are using the Archive Layout in Layout Builder or Looper Provider in any page you can assign a condition and show the placeholder image as you want.

Thanks

I am using Looper provider to show some posts on homepage. So, I would add the condition to the featured image as indicated in the image attached but where do I add the placeholder image?

Hi Tasha,

You need to add two Image elements, one with the condition of Feature Image is set and another one is Feature Image is not set. The placeholder image needs to be added to the second image element where Feature Image is not set condition is added.

Screenshot 2023-05-17 204958

Hope it helps.
Thanks

Thank you for all your help. I followed your steps and I still do not see the placeholder image for the first podcast (see the middle one on this page)

Hello Tasha,

In order to help you with your concerns we need to check your settings I would request you, please share the admin login details meanwhile I would suggest you troubleshoot a few of the common issues before we investigate your settings. Please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin-level username and password

You can find the Secure Note button at the bottom of your posts

Thanks

Hello Tasha,

The Figure element should not have any Conditions.

Only the “Featured Image” and the “Placeholder Image” will have the condition.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.