I want to add a custom image size that is cropped, like this:

add_image_size( 'large-cropped', 700, 300, true );

It works fine. The only problem is that if the image size is for example 500x400, then it will create an image that is 500x300.

I only want it to create an image if the width is at least 700 pixels width.


You will need to do a check for the image size before you add the add_image_size in that case. You can use wp_get_attachment_metadata() to find the size of the image. https://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata

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.