WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I can I check if a post has a thumbnail and if does do something? If doesn't do something else. This is what I have:

 <?php if (has_post_thumbnail()) ?>

 <?php the_thumbnail(); ?>

 <?php else ?>

 <?php the_permalink();?>

 <?php endif; ?>

Any help will be appreciate it.

share|improve this question

You need to use the_post_thumbnail instead of the_thumbnail within the loop. This is how it should be formatted:

<?php if(have_posts()){
share|improve this answer
Sorry I'm kind of new to WP, would this go inside the <?php if (have_posts()) : ?> loop??? – jorame Feb 16 '12 at 3:31
You are correct! The loop populates these functions with the current postdata. :) – Brian Fegter Feb 16 '12 at 3:33
Would this give me any results '<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post()?> <?php if (has_post_thumbnail()) { the_post_thumbnail(); } ?> <?php endwhile; ?> <?php endif; ?>' – jorame Feb 16 '12 at 3:35
Instead of using all the <?php tags see my edited example. – Brian Fegter Feb 16 '12 at 3:36

Your Answer


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.