A while back, we had a pretty hand tutorial on how to work with the featured image functionality in WordPress. We covered a fair bit of useful info in that post. How to get going with the image, how to set sizes and use them, and how to display featured images. One thing we did was show, using a conditional, how to display a default image. Basically if an image isn’t set, display a selected image. A few people have asked how to actually set a default image as the featured image for a post if one isn’t set, rather than just display a default image. Here’s the trick:
First up, I always have to give credit where it is due. This info comes over from Kailan Wyatt over on Wptuts+ – I’d recommend you check out the full article here, it’s a quality read! I’d been meaning to write this up myself, as it’s a feature I use on my personal blog. But, Kailan’s code is simpler, and I like it more! The simple trick is to make sure the default image you want to use is already loaded into your media library, and then get the attachment ID for that image – the ID can be found in the URL to the image, and it is explained in detail in the post I linked above.
Next up, just a bit of code. This block can go in functions.php, or your functionality plugin. I’ll put it in my plugin, as I always want it available. It’s up to you really.
add_action( 'save_post', 'voodoo_default_thumbnail' );
function voodoo_default_thumbnail( $post_id ) {
// Get Thumbnail
$post_thumbnail = get_post_meta( $post_id, $key = '_thumbnail_id', $single = true );
// Verify that post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
// Check if Thumbnail exists
if ( empty( $post_thumbnail ) ) {
// Add thumbnail to post
update_post_meta( $post_id, $meta_key = '_thumbnail_id', $meta_value = 'ID here' );
}
}
}
All you have to do, on line 10 where it says ID here, swap in the numerical attachment ID we discussed earlier. All done! If you were looking for a way to have those featured images attached to each post when you save (if you don’t save one yourself), this is for you!

Nice to see my posts inspiring posts. Thanks for the credit
All the best.
IT was totally one of those things I’d been meaning to figure out for a theme redesign I’m working on. Just never got around to – and your code was very well timed! I threw it into my theme, then figured I should share it for my readers. Great stuff – and somthing I’d been asked for a couple of times.