Title: Default Thumbnail Image
Last modified: August 20, 2016

---

# Default Thumbnail Image

 *  [Michael Moore](https://wordpress.org/support/users/imikedesigns/)
 * (@imikedesigns)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/default-thumbnail-image/)
 * I currently have my archive set to do something like this: if post has featured
   image, use that, if not, use the first image from the post. This is working fine.
   However, I want to take it a step further and say if no image in post, use a 
   default image. This way ill be able to use featured images if needed, if not 
   grab the first image, and if no image has been used, use a default image. Here
   is my current html and logic that is working.
 *     ```
       <div class="post-thumb">
       			<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
         echo PostThumbURL();
       } else {
          echo main_image();
       } ?>&w=200&h=200&zc=1" alt="image" class="frame" /></a>
       		</div>
       ```
   
 * I have tried a few things. It seems like I need to get this code into the logic
   somehow but im not great with php just yet.
 *     ```
       <?php if ( has_post_thumbnail() ) {
       the_post_thumbnail();
       } else { ?>
       <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
       <?php } ?>
       ```
   
 * Thanks for any help.

Viewing 1 replies (of 1 total)

 *  [tribalNerd](https://wordpress.org/support/users/tribalnerd/)
 * (@tribalnerd)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/default-thumbnail-image/#post-2561880)
 * It looks like you need an elseif()
 *     ```
       if ( has_post_thumbnail() ){
          echo PostThumbURL();
       }elseif( the_post_thumbnail() ){
          echo "<img src>";
       }else{
         <!-- all else fails code -->
       }
       ```
   
 * Hope that helps…

Viewing 1 replies (of 1 total)

The topic ‘Default Thumbnail Image’ is closed to new replies.

## Tags

 * [default thumbnail](https://wordpress.org/support/topic-tag/default-thumbnail/)
 * [featured image](https://wordpress.org/support/topic-tag/featured-image/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [tribalNerd](https://wordpress.org/support/users/tribalnerd/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/default-thumbnail-image/#post-2561880)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
