Title: Prevent Post Thumbnail From loading Based on Width
Last modified: August 22, 2016

---

# Prevent Post Thumbnail From loading Based on Width

 *  [lethargio](https://wordpress.org/support/users/lethargio/)
 * (@lethargio)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/prevent-post-thumbnail-from-loading-based-on-width/)
 * I’m using a theme that presents excerpts on the homepage exactly how I like. 
   The problem is that I have 100’s of old posts with images that are too small 
   for the custom image size in the excerpt loop. These images end up stretching
   horizontally and looking terrible. I’d like to set a condition where the images
   only load if they are greater than 300px wide.
 * I do not want to use CSS/jQuery to simply hide the image. I also don’t want adjust
   the cropping or custom custom image size registered since the current settings
   work great for newer posts. This is my image code:
 *     ```
       <?php
       if ( has_post_thumbnail() ) {
            the_post_thumbnail( 'custom-size' );
       } elseif( first_post_image() ) {
            echo '<img src="' . first_post_image() . '" class="wp-post-image" alt="' . get_the_title() . '" />';
       } ?>
       ```
   

The topic ‘Prevent Post Thumbnail From loading Based on Width’ is closed to new 
replies.

## Tags

 * [the_post_thumbnail](https://wordpress.org/support/topic-tag/the_post_thumbnail/)

 * 0 replies
 * 1 participant
 * Last reply from: [lethargio](https://wordpress.org/support/users/lethargio/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/prevent-post-thumbnail-from-loading-based-on-width/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
