X

Set default the_post_thumbnail

Adding this code snippet to your wordpress loop will check if a post thumbnail exists and if not display a default image named img-default.png.



Code Snippet:


<?php
if(has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
?>

Comments  Leave a Reply

  1. thank you

  2. Tweets that mention Wordpress Set default the_post_thumbnail – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com February 11, 2011 at 4:20 pm

    […] This post was mentioned on Twitter by Michael Davis, HTMLfrp. HTMLfrp said: #wordpress Set default the_post_thumbnail http://bit.ly/fe5rS8 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!