I just started to optimize the auto-scaling of images i upload on my wordpress (via Media tool). I added the desired set of custom sizes, which are working just fine. In example :

add_image_size( 'og', 400, 9999 );
add_image_size( 'xxl', 300, 9999 );
add_image_size( 'xl', 200, 9999 );
add_image_size( 'l', 250, 9999 );
add_image_size( 'm', 150, 9999 );
add_image_size( 's', 100, 9999 );

But now i’m wondering if there is a way to put a condition to add_image_size() ? Is it possible to use a set of add_image size only if the uploaded image is less than 150px ?

I’m trying to avoid the creation of very small versions of images that are destined to be big. As wordpress don't scale images up, the idea is to have a rule that does something like : if the file i'm uploading has a width <= 150px then use this additional set of add_image_size().

I’m a beginner in coding so this might not be the right way to do it and i’m open to any suggestion !

Thank you

Your Answer

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

Browse other questions tagged or ask your own question.