admin管理员组

文章数量:1122832

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?

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?

Share Improve this question edited Jun 30, 2020 at 22:56 SherylHohman 8119 silver badges14 bronze badges asked Jan 9, 2017 at 4:29 user3597545user3597545 1711 gold badge1 silver badge4 bronze badges 3
  • You do realize that WordPress does this to reduce server load and speed up your site, right? – Kenneth Odle Commented Jun 20, 2017 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 Commented Jun 30, 2020 at 13:27
  • Related: wordpress.stackexchange.com/questions/216595/… – Jesse Nickles Commented Oct 5, 2023 at 21:37
Add a comment  | 

3 Answers 3

Reset to default 21

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

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.

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/

本文标签: mediaPrevent Wordpress from generating mediumlarge 768px size of image uploads