you can use the post_thumbnail_html
filter hook which passes 5 variables to your hooked function :
$html
– the Output html of the post thumbnail$post_id
– the post ID.$post_thumbnail_id
– the attachment id of the image$size
– the size requested or default$attr
– Query string or array of attributes.
So something like:
add_filter( 'post_thumbnail_html', 'my_post_thumbnail_fallback', 20, 5 );
function my_post_thumbnail_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( empty( $html ) ) {
// return you fallback image either from post of default as html img tag.
}
return $html;
}
Related Posts:
- Missing feature image link function
- Automatically set the featured image
- Get recent posts with thumbnail
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- Add options to featured image
- Linking thumbnail to full size image
- Generating Responsive Background Image Sizes in PHP
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Add a Post Thumbnail to an RSS Feed with custom size
- Make WordPress size and name images for Retina.js
- Why are image thumbnails cropped proportionally (not per dimensions)?
- Display height and width properties with the_post_thumbnail() or related function
- Setting featured image with function, 1 part not working
- Removing the first image in content
- How to set the jpg image compression for specific thumbnail sizes?
- Function to auto-set a featured image that is already in use
- img width and height attributes being set by get_the_post_thumbnail
- Get the 5 lastest Featured Posts from a category
- How to display a default image for post thumbnail using functions.php?
- Change size and crop medium_large images
- Getting Featured Image Caption to Only Show if Populated
- wp_get_attachment_image function size argument not working if I also add a custom class
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Add Featured image column into wordpress admin on pages AND posts
- Post thumbnail not showing in WP admin area for custom post type
- Overwriting Parent Theme’s Image Sizes
- Backstretch.js and thumbnail sizes to reduce loading time
- set_post_thumbnail when user is not logged in
- How to stop twenty fifteen theme from cropping featured images?
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- show first 3 thumbnails of posts in different sizes [closed]
- Set spesific size of featured images
- Can’t generate thumbnail images
- It does not work concatenation in function.php
- How to retrieve the current post’s generated featured image size?
- Check if the image size is available and if not use ‘full’ image size
- is there a way to remove featured image from blog page and single page
- How to hide image-url if no attachment?
- Can set_post_thumbnail be used to remove a thumbnail?
- Can’t locate custom image sizes defined by child theme
- How to add a new image size and apply it to posts only?
- Show Featured Image in else statement
- Change custom featured image size in twentythirteen child theme
- resizing of thumbnails not working
- Featured Image keeps cropping
- show all the posts thumbnails
- struggling with syntax for the_post_thumbnail();
- include w_thumbnail_src in function?
- Custom image sizes showing in Classic Editor only when upladed directly to post
- Which filter fires upon setting a featured image
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- remove_filter function to unhook twentysixteen parent theme function
- Can You Set A Minimum Image Dimension For Resizing Images?
- Featured image on archive page based on post type
- Printing medium sized image
- Sticky – Featured Image
- Frontend Feature image upload not work
- Best way to add image to recent posts widget?
- Slider Thumbnail Size Issue [closed]
- Remove Featured Images from Posts Older Than a Certain Date
- Apply height and width for the_content() inside youtube video tag
- Set thumbnail from URL, by grabbing image in functions.php
- add_theme_support not outputting thumbnails
- Full size image option removing problem
- Image width issue in IE [closed]
- image_size with respect to aspect ratios
- Is mytheme_post_thumbnails() still necessary?
- Get list of years when posts have been published
- Do WordPress’ cron’s clean up expired transients?
- How to add first name & last name to default registration form?
- Masking logout URL
- How can I programmatically create “child” pages on theme activation?
- Warning/Notice about functions.php
- Should everything in functions.php be hooked or filtered?
- Passing arguments to my function with do_action and add_action is not working
- How to find the source of the text for wordpress website? I want to change that text
- when I fetch data from remote mysql database in wordpress built in wordpress function is not working?
- Adding HTML to the end of every post with the Block Editor
- Can I hide certain upload folders in media library [duplicate]
- Function issue with Walker_Nav_Menu [duplicate]
- Calling a Function in Functions.php from an external PHP script
- Custom shortcodes not inserting into visual composer columns
- Post meta not updating
- Why doesn’t is_page(id) work in functions.php?
- Function to alphabetically sort custom post types creating duplicates
- How to parse a shortcode within a shortcode?
- Variables not showing in short code
- Prevent loading of functions
- loginout function customization
- Add Login and logout buttons to top menu bar
- implementing a centralized content “show-do-not-show” toggle?
- How to load a css file depending on the current role
- Add a word after the post url if it is within a specific category
- Unable to declare AOS library in functions
- Will dequeueing in child theme functions.php file prevent Google Fonts from loading?
- Graphic before title – Specific Category
- Edit meta fields from within template
- Adding a meta box fields to child theme options page
- How to programmatically GET (to know) which Sidebar (or) which Menu is being used on Different Pages?
- Remove theme, change theme button and WP version on “Right Now” admin dashboard?