By default, WordPress compresses JPEG images to about 82% quality when you upload them. While this helps speed up your website, it can result in blurry or lower-quality visuals — which is not ideal for photographers, designers, or high-end brands.
To Control Image Quality on Upload in WordPress Use Below Code
Add code to your child theme’s functions.php
file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Avoid adding custom code directly to your parent theme’s functions.php
file as this will be wiped entirely when you update the theme.
How WordPress Handles Image Quality (by Default)
WordPress uses a filter called jpeg_quality
to control compression. For JPEGs, the default value is 82
.
add_filter('jpeg_quality', function($arg){ return 100; });
This changes the quality to 100 (no compression).
Control Image Quality for All Formats on Upload
To globally set compression quality (JPEG/WebP/others) for all image types:
add_filter('wp_editor_set_quality', 'custom_image_upload_quality');
function custom_image_upload_quality($quality) {
return 95; // Value between 1 - 100
}
This works for:
- JPEG
- WebP
- PNG (if using a plugin or system that converts them)
Customize Quality for Different Image Sizes
WordPress generates multiple image sizes (thumbnail, medium, large). You can adjust compression per size by hooking into intermediate_image_sizes_advanced
:
add_filter('wp_generate_attachment_metadata', 'custom_resize_image_quality');
function custom_resize_image_quality($metadata) {
$upload_dir = wp_upload_dir();
$file_path = trailingslashit($upload_dir['basedir']);
foreach ($metadata['sizes'] as $size => $values) {
$image_path = $file_path . $values['file'];
$image = wp_get_image_editor($image_path);
if (!is_wp_error($image)) {
$image->set_quality(95); // Set your custom quality
$image->save($image_path);
}
}
return $metadata;
}
This gives you precise control of compression after WordPress generates resized images.
Disable All Compression (for pixel-perfect uploads)
If you want to completely disable image compression:
add_filter('jpeg_quality', '__return_max');
add_filter('wp_editor_set_quality', '__return_max');
This sets image quality to 100 for all editors and image processing tasks.
Prevent WordPress from Resizing Uploaded Images
If you want to only keep the original image:
add_filter('intermediate_image_sizes_advanced', '__return_empty_array');
Note: This will disable all auto-generated sizes (thumbnail, medium, large), which could break layouts depending on your theme.
Use WebP with High Quality
If you’re using WebP conversion via plugins like Smush, ShortPixel, or EWWW, ensure you configure those plugins to use quality above 90
or even 100
if your use-case requires sharp visuals.
Also, with WordPress 5.8+ supporting WebP natively, this filter still applies:
add_filter('wp_editor_set_quality', function($quality) {
return 90;
});
Controlling image quality gives you better brand presentation, sharper visuals, and more power over optimization. Don’t just rely on default WordPress behavior — tailor it to fit your site’s design goals.
Would you like help turning this into a plugin or adding a settings UI for non-dev users? I can help you build that next!