Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently using the_post_thumbnail(); to display featured images in my pages.

Is it possible to set a fallback placeholder image in the event a featured image hasn't been set?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use has_post_thumbnail() as condition and change output accordingly.

Example from Codex:

if(has_post_thumbnail()) {
    the_post_thumbnail();
} else {
    echo '<img src="'.get_bloginfo("template_url").'/images/img-default.png" />';
}
share|improve this answer
    
Is it possible to implement this in the functions so it would work for all instances of the the_post_thumbnail across the site? –  Vince Pettit Mar 2 '12 at 11:35
1  
@Vince Pettit from quick look that should be doable by making use of post_thumbnail_html filter. –  Rarst Mar 2 '12 at 12:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.