WordPress缩略图体积远超原图,如何优化生成或针对该图禁用?
Hey there! Let's figure out why your smaller WordPress thumbnail is actually bigger than the original, and fix this issue for good.
First, the root cause: Your original 2880x1996 PNG is probably optimized (maybe you used tools like TinyPNG or OptiPNG to compress it down to 460KB), but WordPress by default generates PNG thumbnails with no lossy compression—it just resizes the image and saves it as a raw, unoptimized PNG. That's why a smaller resolution ends up being way larger in file size.
Here are your two main solutions, depending on whether you want to fix the thumbnail compression or just disable that specific size entirely:
This is the best approach if you still need the 1920x1331 thumbnail size but want it to be properly compressed.
Option 1: Add Custom Code to Enable Compression
You can tweak WordPress's image editor to apply compression when generating PNG thumbnails. Add this code to your theme's functions.php file (or better yet, a custom plugin, so it doesn't get lost when you update your theme):
add_filter('image_editor_save_pre', 'optimize_my_png_thumbnails'); function optimize_my_png_thumbnails($image) { // Check if we're using the GD image editor (most common) if ($image instanceof WP_Image_Editor_GD) { // Set PNG compression level (0 = no compression, 9 = maximum compression) $image->set_quality(9); } return $image; }
Note: For PNGs, the set_quality() value maps to GD's compression level (0-9). Start with 9 (max compression) and test—you'll get a much smaller file size without noticeable quality loss for screenshots.
Option 2: Use an Image Optimization Plugin
If you don't want to mess with code, install a plugin like ShortPixel Image Optimizer or Smush. These tools automatically compress all new thumbnails when they're generated, and you can also bulk-optimize the existing 1.6MB thumbnails to shrink them down to a reasonable size. Just install the plugin, follow the setup prompts, and let it do the work.
If you don't need the 1920x1331 thumbnail at all, you can turn it off entirely.
Step 1: Check WordPress's Default Media Sizes
Go to your WordPress dashboard → Settings → Media. Look at the "Large size" dimensions—if it's set to 1920x1331, you can either:
- Change the dimensions to something that makes sense for your site, or
- Set one of the values to
0to disable the large size thumbnail entirely.
After saving changes, you'll need to delete existing thumbnails (use a plugin like Regenerate Thumbnails to clean up old files and generate new ones if you changed the size).
Step 2: Remove Custom Image Sizes (If Added by Your Theme)
Sometimes themes register custom thumbnail sizes. To find out all registered sizes, you can temporarily add this code to functions.php and load any front-end page (then delete it after):
var_dump(get_intermediate_image_sizes());
This will show you a list of all thumbnail size names. If you see one that matches the 1920x1331 dimensions, remove it with this code:
add_action('after_setup_theme', 'remove_unwanted_image_sizes', 11); function remove_unwanted_image_sizes() { // Replace 'theme-large-size' with the actual size name you found remove_image_size('theme-large-size'); }
Step 3: Make ACF Gallery Load the Original Image (As a Last Resort)
If you want to skip thumbnails entirely and use the original image, modify your ACF Gallery code. Instead of loading the large size, load the raw url of the image:
Original code (loads thumbnail):
$gallery_images = get_field('your_gallery_field_name'); if ($gallery_images) { foreach ($gallery_images as $image) { echo '<img src="' . $image['sizes']['large'] . '" alt="' . $image['alt'] . '">'; } }
Modified code (loads original):
$gallery_images = get_field('your_gallery_field_name'); if ($gallery_images) { foreach ($gallery_images as $image) { echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] . '">'; } }
Warning: This will load the 2880px image for all users, which might slow down your page load times. Only do this if you're sure your visitors have fast internet, or pair it with responsive image attributes to serve smaller sizes to mobile users.
内容的提问来源于stack exchange,提问作者Doug Neumann

