Skip Navigation

[Resolved] Set specific images in case Featured Image is empty

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I set another (predefined) image if the Posts featured image is left empty?

Solution:
There are 3 options:
1. use HTML Conditional to actually display a predefined image in case no Featured Image is saved for the post. This does not update the post, it just displays this in the front end.
2. Save a default image when the post is saved without a Featured image with custom code
3. use a Plugin that does #2 above.

The first solution is achievable within Toolset, the second not.
Both are documented on below links:

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-if-a-post-has-a-featured-image

https://www.wpbeginner.com/wp-themes/how-to-set-a-default-fallback-image-for-wordpress-post-thumbnails/
https://enviragallery.com/how-to-set-a-default-featured-image-in-wordpress/

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by markus 5 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#1214863

I have a post type "News" and a selectable category "press-release". Press releases usually don´t have an image but I want to automatically set a featured image from the media library if the featured image field is empty.
I am checking whether the featured image is empty with this

[wpv-conditional if="( empty($(_thumbnail_id)) )"]
  featured image is EMPTY
[/wpv-conditional]

but how can I actually set the featured image in my content template so it gets recognized as featured image (e.g. in grid views)?

#1214894

How to check upon the featured image in a HTML condition is shown here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-if-a-post-has-a-featured-image

There is also a sample on how to display that featured image, it's done with https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153425

I am not entirely sure what you mean by "but how can I actually set the featured image in my content template so it gets recognized as featured image (e.g. in grid views)?"
Can you elaborate on that?

#1214907

Ok.what I can do with Toolset so far is show an alternative image if a featured image was not set. That is easy and clear. This method does not help if I need a featured image e.g. for grid views (e.g. in visual composer) because if I refer to this field

[wpv-post-featured-image size="full"]

in a content template it still would be empty.

My question is whether there is a method to "tell the system" to replace a missing featured images of a specific post type with a default image from the media library?

#1216773

Do you mean to actually assing an Image to a post if that post has no such Featured Image?
That is only possible with custom PHP code, but within an HTML condition, this is not needed, because "if the field is empty" then "display something else" is exactly the same, unless that the image is not assigned to that post with missing Featured Image.

If you need to assign a default image to a post if that post has no custom set Featured Image you will need custom code, best hooked to the save_post action (when the post is created or updated).

There are plenty of code examples and even plugins doing this, but it's not possible within Toolset itself.
One such example is here, it seems to do what you need:
hidden link
You can also do that manually:
hidden link > Method 2

#1218156

My issue is resolved now. Thank you!