7

I have followed guidelines to prevent wordpress from generating many different sizes for individual images uploade via the sizes for thumbnail, medium and large to 0 in Settings>Media and have gotten rid of all instances of add_image_size and set_post_thumbnail_size in the functions.php file of my theme. However, when I upload new images, Wordpress is still generating a 768px width version beyond the original full size. I believe it has something to do with this update but am wondering if there is any way to prevent it from happening? I believe I have read some threads where people have achieved it inadvertently trying to do something else, but I'm looking for a clearcut method.

  • 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
11

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();

  • 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
3

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.

2

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/

  • 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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.