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
- Programmatically get images by URL and save in uploads folder
- How to automatically add rounded corners to thumbnails?
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- Download an image from a webpage to the default uploads folder
- WP 4.4. responsive images browser choosing the “wrong” one
- How to change image type for specific size?
- Remove images (files) that were generated when using add_image_size()
- Is there a hook which fires after all thumbnails are generated?
- is it possible to replace the use of gd_lib with imagick or ImageMagick?
- Featured image shortcode
- Using Images in WordPress – Best Practices
- How to find attachment by it’s name?
- Change WordPress image URLs via filter
- get_the_post_thumbnail_url with an unregistered size
- Cropped featured image replaces original image in gallery
- Image Scaling using get_the_post_thumbnail issue in WordPress
- Any easy way to automatically set the first inline image in a post as the thumbnail?
- Change html structure of all img tags in WordPress
- Remove title attribute from images
- Insert an image into a post by API
- How to limit number of images being printer out in “Set Featured Image” pop up?
- Creating a rotating header /image slider using theme customization
- Black and White thumbnails
- Adding HTML within an image title attribute
- Programatically creating image attachments from local URLs and setting featured image
- How can I add the “Use as featured image” to a custom metabox?
- set_post_thumbnail_size not cropping featured images, but reducing proportionally
- How to grab first image attached to post and display in RSS feed?
- Double thumbnails?
- No srcset for hard-cropped thumbnails
- Is it possible to prevent users from uploading small images?
- Can’t Display Featured Image in RSS Feed
- Displaying a featured image (only img url) as the img src?
- 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
- Limit author image size
- When displaying the featured image, is has_post_thumbnail() necessary?
- Find posts without featured image? [duplicate]
- How do I add a featured image to a single post page?
- Add a featured image in my theme?
- Disable wordpress image sizes generation
- Get original image from thumbnail URL
- What’s the best “insert all images” plugin?
- Any way to “combine” galleries or show multiple galleries as one?
- Featured Image .svg height and width 1px only
- Image Editor does not affect custom sizes!
- How to check if user is uploading/setting an image as a featured image?
- Images are randomly deleted from server
- Frontend Post – Allow Only Image File Upload
- attach unattached featured images to respective posts
- Can I the caption shortcode to set caption to a data attribute, and with the image’s alignment intact?
- Images not working using Featured post
- Add instructions to featured image
- WordPress reduces the full size image and uses it as the original
- How do I get more image editing options in the admin?
- Thumbnails are bigger in size than the original image
- Lazyload post thumbnails
- 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
- Photography Based Design – Multiple Images Per Post
- Special purpose photos with each post
- SVG Featured image not shown in twitter
- Featured images not displaying at full resolution
- Woocommerce featured image of page – not product
- Set Post Image Using Shortcode
- Print specific image size in galley loop
- WordPress crops images differently on retina screens?
- Can’t seem to attach uploaded image to post and set it as thumbnail
- wp_upload_bits does not retrieve images that do not have an extension
- Big Image on Featured Post, Normal on Single Post
- offload media to external services [closed]
- Store Snapshot created via wordpress to use with lightbox
- How do I Add images uploaded in the post to a default custom field
- How to stop thumbnail generation from some images and different size thumbnail generate
- Update old Post image metadata to ‘thumbnail’ wp_attached_file
- How to stop wordpress always displaying full-res images
- How can I add a “data-pin-nopin” the featured image html?
- Get ALT attribute from title post (code not work)
- WP keeps looking up post thumbnail on https even though wp-config says http
- Images stopped loadding after adding SSl
- WordPress PNG compression issue
- How to replace images?
- Using custom image resizing script in a page
- Fixing image names for a site being restored
- Setup Featured image on all posts from thesis thesis_post_image custom field?
- Image LazyLoad plugin not loading jQuery dependancies with wp_enqueue_script in WP 3.3.1
- Export xml use/import images from theme directory
- Custom Loop, Match Category with Page: How to display post featured image?
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- Redirect to another page using contact form 7? [closed]