Lower Quality for Small Thumbnails, Higher for Large Images
Saves small thumbnails with stronger compression and large images with higher quality, so grids load fast while hero images stay crisp, instead of one quality for everything.
Opens WPIDE on
Code
// Width threshold and the two quality levels.
$wpide_small_size_px = 400;
$wpide_small_quality = 70;
$wpide_large_quality = 88;
add_filter( 'wp_editor_set_quality', function ( $quality, $mime_type, $size = array() ) use ( $wpide_small_size_px, $wpide_small_quality, $wpide_large_quality ) {
if ( ! in_array( $mime_type, array( 'image/jpeg', 'image/webp' ), true ) || empty( $size['width'] ) ) {
return $quality;
}
return (int) $size['width'] <= $wpide_small_size_px ? $wpide_small_quality : $wpide_large_quality;
}, 10, 3 );
Notes
Needs WordPress 6.8+, which tells the quality filter which size is being made; applies to JPEG and WebP images created from now on.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.