13

I prevent WordPress from generating thumbnail, medium, and large image sizes for images I upload to the Media Library, by setting their dimensions to 0 from the dashboard: Settings -> Media panel.

I have also gotten rid of all instances of add_image_size and set_post_thumbnail_size from the functions.php file of my theme.

However, when I upload new images, WordPress is still generating a 768px width version (called 'medium_large') from my original full size image. I believe it has something to do with this update.

Is there is any way to prevent this from happening?

  • You do realize that WordPress does this to reduce server load and speed up your site, right? – Kenneth Odle Jun 20 '17 at 1:52
  • You are correct. The medium_large image size appeared in WordPress 4.4, together with responsive images feature. It has fixed width 768 px, and proportional height. This is hard coded into WordPress, unlike the other default image sizes. I also am removing it, however WordPress and other themes may rely on having this image size available to work properly. Keep this in mind if you ever need to switch to a default WordPress theme temporarily for debugging, or when trying new themes. If the size wasn't generated at image upload, other themes will not automatically generate it when needed – SherylHohman yesterday
17

To remove the medium_large image size you can try to remove it with the intermediate_image_sizes filter:

add_filter( 'intermediate_image_sizes', function( $sizes )
{
    return array_filter( $sizes, function( $val )
    {
        return 'medium_large' !== $val; // Filter out 'medium_large'
    } );
} );

Not sure if you're trying to remove all the intermediate sizes, but then you could try out:

add_filter( 'intermediate_image_sizes', '__return_empty_array', 999 );

where __return_empty_array()` is a built-in core function.

We should note that it's not possible to remove it with

remove_image_size( 'medium_large' );

because it's not added with add_image_size() and therefore not part of the $_wp_additional_image_sizes global array or wp_get_additional_image_sizes();

| improve this answer | |
  • yes it's also possible to change the medium_large_size_w option to 0, but we can't do it via /wp-admin/options.php because it seems to have problem with a 0 value there (that's actually what I tried first before writing the answer ;-), so we need to set it via settings API or manually in the wp_options table. – birgire Jan 9 '17 at 10:57
8

Remove image size the same way wordpress core code does it:

add_filter('intermediate_image_sizes', function($sizes) {
    return array_diff($sizes, ['medium_large']);
});

Keep in mind that medium_large is generally a good size to have in srcset, only remove it if you have understanding how srcset works, if you have similar sizes there already.

| improve this answer | |
3

this will work


function paulund_remove_default_image_sizes( $sizes) {
    unset( $sizes['medium_large']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced','paulund_remove_default_image_sizes');

https://developer.wordpress.org/reference/hooks/intermediate_image_sizes_advanced/

| improve this answer | |
  • While this did not create the image itself it did however create the entry in the attachment array, so a fake entry with the 769x at the end of the url. Using the default filder intermediate_image_sizes did get rid of making the image and not showing an entry for it in the array. – lowtechsun Mar 9 '18 at 1:20

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.