Display thumbnail only if requested size exists

When I use the functions that get and output the post thumbnail, they will display the requested thumbnail in the size you specify, but if this size doesn’t exist they will display the thumbnail in the original size and force the browser to resize it.

How can I force them to display a placeholder like “no image” in case the requested size doesn’t exist?

7 s
7

Assuming the question is about wp_get_attachment_image_src.
It could be also about wp_get_attachment_link, but, although related, this analysis doesn’t includes it.


Got aware of this issue answering this question: How can I view all WP generated thumbnails in Media Manager?.
Refer to it to see a working code regarding the issue on this Question.

And it lead to this WordPress forum topic.


The function wp_get_attachment_image_src( $attachment_id, $size, $icon ) returns an array containing:

[0] => url  
[1] => width  
[2] => height  
[3] => is intermediate

If [3] is false, the original image data is returned.


Both wp_get_attachment_image_src and wp_get_attachment_link rely in the function image_downsize, inside /wp-includes/media.php.
And that’s where this 4 items array is being returned.

Leave a Comment