Title: the_post_thumbnail IF ELSE function issue
Last modified: August 21, 2016

---

# the_post_thumbnail IF ELSE function issue

 *  Resolved [lschoen114](https://wordpress.org/support/users/lschoen114/)
 * (@lschoen114)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/)
 * Hello,
 * I have the following code in my single.php file, which grabs the featured image
   and displays is as a background image for that post.
 * `<figure class="thumblucas"><?php the_post_thumbnail('slider-post-thumbnail');?
   ></figure>`
 * I am trying to create an IF function that say, If there is a featured image, 
   display that image using the code above. If there is not one, display a generic
   chosen image. I have found the following code which would work, but its not working
   with what I am trying to do.
 *     ```
       <?php
       // Must be inside a loop.
   
       if ( has_post_thumbnail() ) {
       	<figure class="thumblucas"><?php the_post_thumbnail('slider-post-thumbnail'); ?></figure>;
       }
       else {
       	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';
       }
       ?>
       ```
   
 * Is there any way to accomplish something like this?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/#post-4082436)
 * > but its not working with what I am trying to do
 * what is the result?
    do you have the _thumbnail-default.jpg _image located in
   the /images folder of your theme?
 *  Thread Starter [lschoen114](https://wordpress.org/support/users/lschoen114/)
 * (@lschoen114)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/#post-4082460)
 * The result is that is breaks the entire page.
 * For some reason the if code “<figure class=”thumblucas”><?php the_post_thumbnail(‘
   slider-post-thumbnail’); ?></figure>” is not accepted when I try and do it.
 * All that shows up is a white page.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/#post-4082484)
 * you have missing php tags;
 * try:
 *     ```
       <?php
       // Must be inside a loop.
   
       if ( has_post_thumbnail() ) { ?>
       	<figure class="thumblucas"><?php the_post_thumbnail('slider-post-thumbnail'); ?></figure>
       <?php }
       else {
       	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';
       }
       ?>
       ```
   
 *  Thread Starter [lschoen114](https://wordpress.org/support/users/lschoen114/)
 * (@lschoen114)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/#post-4082508)
 * That worked!
 * Thank you for spotting that for me!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘the_post_thumbnail IF ELSE function issue’ is closed to new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [lschoen114](https://wordpress.org/support/users/lschoen114/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/the_post_thumbnail-if-else-function-issue/#post-4082508)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
