I've added an image size of 370x150 which works, but if I upload an image to those exact dimensions get_post_thumbnail() no longer works as expected. If I look into my uploads folder I'll have a thumbnail, medium, and full along with a 1x1. I add the image size like so:

add_image_size('homepage_featured', array(370, 150));

and call that image like so:


which then pulls up the 1x1 image size. I could probably circumvent this by adding a conditional before my thumbnail call which tests if that size exists:

$thumb = get_the_post_thumbnail($post->ID, 'homepage_featured');
$thumbArr = explode('width="', $thumb);
if(!empty($thumbArr) && is_numeric($thumbArr[1][0]) && $thumbArr[1][0] >= 370)

but that seems silly. Is this a normal thing or is it a problem with my custom theme? Is there a better way to test if a certain thumbnail size exists than the above method?



Specifically note that the syntax is

add_image_size( $size, $width, $height );

What is likely happening is the array is resolved to false and defaulting to 0, as well as height.

As far as I know you can't have a 0x0 image, so it becomes 1x1 for that size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.