One simple method is to filter post_thumbnail_html
, to add in a default image link:
<?php
function wpse55748_filter_post_thumbnail_html( $html ) {
// If there is no post thumbnail,
// Return a default image
if ( '' == $html ) {
return '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" width="150px" height="100px" class="image-size-name" />';
}
// Else, return the post thumbnail
return $html;
}
add_filter( 'post_thumbnail_html', 'wpse55748_filter_post_thumbnail_html' );
?>
You can make this filter more complex, but this should get you started.
Related Posts:
- How to create thumbnails with a fixed width, so all of them will have the same width?
- Remove image classes from post thumbnail output
- Filter to remove image dimension attributes?
- Stop wordpress from hardcoding img width and height attributes
- How to automatically add rounded corners to thumbnails?
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- WP 4.4. responsive images browser choosing the “wrong” one
- Remove images (files) that were generated when using add_image_size()
- Is there a hook which fires after all thumbnails are generated?
- Featured image shortcode
- Using Images in WordPress – Best Practices
- How to find attachment by it’s name?
- Cropped featured image replaces original image in gallery
- Image Scaling using get_the_post_thumbnail issue in WordPress
- Change html structure of all img tags in WordPress
- How to limit number of images being printer out in “Set Featured Image” pop up?
- Black and White thumbnails
- How can I add the “Use as featured image” to a custom metabox?
- How do I delete thousands of unattached images?
- How to output placeholder image if no featured image set?
- Featured Images on Front Page
- Download button for Featured Image in every post – automatically
- How to remove link from an image in a post?
- Removing Title Tag from Thumbnails
- Show prev and next post links for parent post of current image in attachment page?
- Change html structure of all img tags in WordPress
- Get original image from thumbnail URL
- Any way to “combine” galleries or show multiple galleries as one?
- Image Editor does not affect custom sizes!
- How to check if user is uploading/setting an image as a featured image?
- attach unattached featured images to respective posts
- Thumbnails are bigger in size than the original image
- How can I make all post image uploads have data-width and data-height attributes automatically by default?
- Exclude featured image from gallery in wp-admin
- SVG Featured image not shown in twitter
- Featured images not displaying at full resolution
- wp_upload_bits does not retrieve images that do not have an extension
- Update old Post image metadata to ‘thumbnail’ wp_attached_file
- WP keeps looking up post thumbnail on https even though wp-config says http
- Images stopped loadding after adding SSl
- How to replace images?
- Fixing image names for a site being restored
- Setup Featured image on all posts from thesis thesis_post_image custom field?
- Export xml use/import images from theme directory
- Get custom thumbnail sizes [duplicate]
- Should I not compress my jpeg files before uploading to avoid double compression?
- Custom responsive ‘featured image’ sizes
- the_post_thumbnail(‘medium’) setting some images width=1 height=1
- Generating a certain sized thumbnail on the fly?
- Images give 404 after changing default domain
- How do you import images from a URL in your post?
- How to set uploaded image as featured image wordpress
- Featured Image If Else Condition
- What can i do add title to ‘large’ image?
- Retrieve Image Attachments Getting Post Thumbnail Image First
- Height and width attribute not setting by the_post_thumbnail
- How to force WordPress to upscale images?
- What sense makes medium_large_size_h => 0?
- How to set minimum required size for featured image?
- All Images not calling alt text
- How do I link a featured photo to it’s post?
- Can we use featured image as third party website image URL
- Show (print) featured image all dimensions (height, width)
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- add_image_size not working
- Serve different images per screen size and cache possible?
- Product Images Low Quality After Updating From WP 3.5 to 4 [closed]
- Convert featured images into “product images”
- Resize uploaded images [duplicate]
- How to use the thumbnail size with catch_that_image
- Thumbnail and image management
- my featured image of wordpress are not showing in the front end though image are uploaded in media library
- How to change Gallery image url in product page ? In function.php?
- How is called this thumbnail slider feature
- Custom image size not displaying with wp_get_attachment_image()
- How to delete original image file after upload and resize
- An error has occurred during the upload process in wordpress version 5.3.2
- Force WordPress to always generate a thumbnail for original image
- Show featured image in all posts
- Get post thumbnail in specific size
- WordPress 5: including larger thumbnail image sizes in srcset than I have set
- How to make image uploads default to full size?
- How to add the option to choose between sizes for featured image within post editor?
- featured image in custom poste type (backend)
- Custom Background for each page and post
- Using custom field to change alt text for a featured image
- Upload image without resizing but insert in post with resizing
- Get “Image CSS Class” value from the Advanced Options section
- Dinamically modifying attributes of images on posts
- How to display image thumbnails on the search results page?
- Get custom size of thumbnails
- How to add multiple images in a page
- Only User Upload image Http Error
- Black and White Thumbnail in WordPress Gallery
- Remove “align” attribute on images
- Saving a post, content filtering and user levels
- Slider do not add alt attribute. Cant get alt attribute from a media library!
- How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?
- Uploaded Media Images on Site
- Edit multiple posts featured image