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 |3 Answers
Reset to default 21To 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
版权声明:本文标题:media - Prevent Wordpress from generating medium_large 768px size of image uploads? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296147a1929725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
medium_large
image size appeared in WordPress 4.4, together with responsive images feature. It has fixed width768
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