Change the way WordPress compresses JPEG images

If you are uploading bunch of JPEG images on your WordPress website, you might have noticed they are losing on their original quality. If you have wondered if WordPress is to blame, now you will have your answer – yes, it is!

Once you upload an image in JPEG format, WordPress automatically changes the compression and decides you want the image to lose its quality. To be more specific, WP uses 90% compression on your JPGEs. That’s great if your images are only there to be used as post thumbnails or to be shown in a post, but if you are uploading your photographs, you want them to be as best as possible, right?

Luckily, you will only need one line of code to change this.

Stop JPEG images compression:

If you don’t want your JPEG images to be compressed, simply copy and paste the following code in your functions.php file:

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

Don’t forget to save the changes and you’re ready to upload new images.

On the other hand, images might not be that big of a deal for you. So you might want them to be even more compressed and save you time on loading your site. If you change the last number in that line of code, you will be changing the quality of newly uploaded images.

Compress JPEG images even more:

The lower the number, the more images will be compressed. For example, to compress those JPEGs even more, you will need this code:

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

Don’t forget; default compression level is 90.

Important: This will only effect images that you upload after you pasted the code in the functions.php. To change size and quality of the images you already have in the library, you will need a plugin. See how to regenerate additional image sizes.


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *