Skip to content

How to Change, Disable Image Compression in WordPress

Did you know you can change WordPress images compression, else WordPress will make your uploaded images and pictures blurry and pixelated?

I used to get very surprised when I used to load HD or 4K images only to find that when I inserted images in the WordPress post the quality of images was suboptimal. I try to figure workaround for a long time till I realized that WordPress compresses images by default.

Image Compression in WordPress

compress images

Sometime back WordPress used to compress images by 90% and now after site speed has become important, they compress images by 82%.

If you are a casual blogger and possibly the default WordPress image compression is not of any issue to you but if you run a photoblog or share your mini drone photos or landscape scenery and are very particular about uploading high image quality then it is important that you disable WordPress image compression so that you can get high-quality images without any loss of image quality.

PNG is a lossless file format, which will give you exceptional high image quality, but the sizes are much larger than the lossy JPEG format, which is preferred the most.

Change WordPress Image Compression

So here’s the code choose to that will allow you to change image compression in WordPress easily and get the image quality of your choice.

This code has to be added to the theme functions.php file on a new line. This code will disable JPEG image compression and retain image quality if uploaded JPEG image. These WordPress hooks we want to edit are jpeg_quality and wp_editor_set_quality

The key value we added here is 100 you will notice.

add_filter('jpeg_quality', function($arg){return 100;});
add_filter( 'wp_editor_set_quality', function($arg){return 100;} );

If you want to increase image compression, you might want to replace 100 by 70.

add_filter('jpeg_quality', function($arg){return 70;});
add_filter( 'wp_editor_set_quality', function($arg){return 70;} );

You might also decide not to use the default 82, and choose a lesser compression like 90

add_filter('jpeg_quality', function($arg){return 90;});
add_filter( 'wp_editor_set_quality', function($arg){return 90;} );

Note that the final quality will depend on the quality of the image uploaded and the image resolution. If your image is already compressed before upload, WordPress will compress it further. So if you want to keep the highest quality, then upload an uncompressed JPEG image at 100% quality and 0% compression and stop WordPress image compression.

Why Compress Images?

With the growing emphasis on core web vitals to increase your website speed, using low size fast-loading images has become very popular.

Due to people viewing websites on large screens the default width settings of blogs have become very large due to which people upload large images to give a good visual appeal but large images also have a larger size.

There are many image optimizing services and image compression WordPress plug-ins that optimize images to make them load faster, and webp has become a new standard especially after Google Pagespeed keeps emphasizing that it makes the images 30% smaller.

Thus WordPress compresses images by default, but you can fix this issue at this step. Else you might double compress images leading to poor image quality and a bad user experience.