I’ve noticed that WordPress does not generate a thumbnail for an image if the uploaded image’s size is the same as the thumbnail’s size.
To make this clear, here is an example:
I have an image with a size of 300x200px
. My thumbnail’s size in the WordPress setting is also 300x200
. So, when i upload this image, no thumbnail of 300x200
size will be generated, because the uploaded image itself is considered a thumbnail to WordPress!
I’ve tracked it down to wp_generate_attachment_metadata()
function, which decides not to crop an image if the image’s size is equal to a thumbnail’s size. Here is the link to this function’s content.
This function has a filter, as the following:
apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
How can i make this function to make the thumbnail, no matter what size?
Thanks.
UPDATE 1:
Following the answer by @birgire, i have included my custom multi_resize()
function in the question:
function multi_resize($sizes) {
$sizes = parent::multi_resize($sizes);
//we add the slug to the file path
foreach ($sizes as $slug => $data) {
$sizes[$slug]['file'] = $slug . "https://wordpress.stackexchange.com/" . $data['file'];
}
return $sizes;
}
I’m using this function for some other purposes, mentioned this question.