• lethargio

    (@lethargio)


    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.