Set a Fallback Image for Post Thumbnails WordPress

Written by on June 27, 2011 in WordPress - No comments
wordpress-thubmnail

If you’re using WordPress thumbnail images in your theme it’s a good idea to set a default, or “backup” option since you don’t have or don’t want to use a thumbnail on a specific post. So basically you’re saying “if the post has a thumbnail use the thumbnail” OR “if no thumbnail exists use this image”.

Here is the code to pop into your theme in the place where you want your thumbnail image to be placed.

<?php
    // If post thumbnail exists, if not use this image
    if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) {
        the_post_thumbnail();
    }

     else {
        echo '<img src="http://examplesite.com/images/blah.jpg" />';
    }
?>

About the Author

Mike Ilsley "ilz" is a Boston based website designer, front-end developer, WordPress addict, owner of Beantown Design, and exclusive ThemeForest author. Check him out on Twitter, Facebook, Google+ and don't forget to subscribe to the WebDesign&Such email RSS feed. Also, check out his latest project, jQueryMobileShowcase.com.