Recently, one of our readers asked if it was possible to change the image compression setting in WordPress.
WordPress compresses your images by default for better performance. However, this will result in slightly lower quality.
In this article, we will show you how to increase or decrease JPEG image compression in WordPress.
Every time you upload a JPEG image to your WordPress website, it automatically compresses the image to 90% quality. Way back in WordPress 4.5, this number was further decreased to 82% to improve site performance for mobile users.
If you are a photographer who wants to showcase high-quality images on your website, then you can turn off image compression in WordPress.
To make it easy, we have created a video tutorial on how to change WordPress JPEG image compression that you can watch below.
However, if you just want to follow text instructions, then you can follow our step-by-step tutorial on how to change WordPress JPEG image compression in WordPress.
How to Disable Image Compression in WordPress
All you need to do is paste the following code into your theme’s functions.php file manually or by using a code snippet plugin like WPCode (recommended).
If you haven’t done this before, you may like to see our guide on how to add custom code to your WordPress website:
add_filter('jpeg_quality', function($arg){return 100;});

When you set the value to 100, it means that WordPress compresses the image at its highest quality.
If you are not a photographer or an artist, then you would probably not see much of a difference in quality. But for those who work with high-quality images on a daily basis, the difference in quality is obvious.
How to Increase Image Compression in WordPress
There are definitely performance benefits to leaving the compression quality as is. If you want, you can change the number from 100 to 80 or something lower to squeeze a few more kBs, then all you have to do is paste the following code:
add_filter('jpeg_quality', function($arg){return 75;});

When you make these image quality changes, you also want to make sure that you regenerate your thumbnails.
We hope this article helped you learn how to change JPEG image compression in WordPress. You may also want to see our guide on how to create a contact form in WordPress or our expert pick of the best Instagram WordPress plugins.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Tom says
I tried this so many times, and many different variations of this code but it never works. I don’t know what else to do. Every time I upload a photo, I can see that the quality is blurrier. Do you have any other tips?
WPBeginner Support says
Please ensure you do not have any other plugins that compress/optimize your images as that is the most common reason the images would be compressed. The other common reason would be if your theme is resizing the images in which case we would recommend taking a look at our article below!
https://www.wpbeginner.com/beginners-guide/wordpress-image-sizes-beginners-guide/
Admin
Tom says
Thanks for the reply. Just an update: It turns out it was my hosting company that was compressing my photos. They had a CDN feature that was automatically enabled that I didn’t know about. After I disabled it, my photos are fine now.
Purnendu Mukherjee says
Hi,
If we use a image compression plugin like Smush, Optiomole or any other, will my images be compressed twice (once by WordPress and then by the plugin)??
WPBeginner Support says
You would want to check with the support for the plugin you plan to use but most should have the ability to cancel the standard compression.
Admin
Rigsby says
Hello, once the php is added, will that override any image compression plugin that is installed at a later date or does the plugin override the code? It will be hard to remember that your php was once added a long time ago, and therefore it may cause headaches wondering why the plugin isn’t working correctly.
Thanks : )
Tom says
” If you want, you can change the number from 100 to 80 or something lower… then all you have to do is paste the following code:”
ADD THE CODE WHERE???
WPBeginner Support says
As with the code above, you would place it in your theme’s functions.php or a site-specific plugin. To protect from theme updates we would normally recommend a site-specific plugin:
https://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/
Admin
rob says
Hi – Do images need to be reuploaded for it to take effect?
Also, will this work for png images or do I need to change jpeg to png in the php code?
Thanks
WPBeginner Support says
This would only apply to new images and not your current images and you do not have to worry about PNG compression.
Admin
Netgoondoo says
Hi, is this code snippet valid in php 7?
WPBeginner Support says
The snippet should still be working
Admin
puspa chaulagai says
hey, I am from love and fun quotes I found your article while I searching for how to stop auto compressing images on WordPress. I try your code but it still not working. When I change the theme it’s work but in which theme I apply it doesn’t work. How to remove auto image compress by theme please help.
WPBeginner Support says
You would want to reach out to the support for your specific theme for them to be able to assist with their specific compression.
Admin
Sukanya says
I have not seen much of a difference even after regenerating. Am I missing something?
Heather Wilson says
Hello,
I am working with wordpress.com – can you do this through the customizing CSS menu, and if so how? I am brand new to coding.
WPBeginner Support says
Hi Heather,
No, you cannot. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
Karlo Gavric says
Even I change compression to 100, my images looks so bad in quality, only if I use full sized (widht 1300+px) is OK, but if I use Large file which is 900px, it is horrible.
I added code to change compression in functions.php, contacted my theme supplier and hosting support, they don’t have any compressions turned on.
Any ideas?
WPBeginner Support says
Hi Karlo,
Try deactivating all plugins and switching to a default theme, after that upload a large image and see if that fixes it.
Admin
Karlo Gavric says
Hi,
I’ve tried it, but the problem still persists. Tried also just changing a theme with plugins enabled / disabled, no change (?! feeling confused really ?!)
nospampls says
you need to set your large file size to a higher image size. wordpress will automatically crop your images…
Anne says
what does this mean
Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.
Thank you
Eoin says
It means that you need to use an external editor to edit the files because the WordPress editor is restricted.. There are plugins available for editing theme files through the wordpress admin which you can look up on the Add New Plugin page, otherwize, you need to download your theme files using a FTP software, update the functions.php file and upload it back to the theme folder on the server. If you are not sure about FTP, I would just look for an theme editor plugin so you can do it in the wordpress admin, but make sure to deactivate the plugin when you are finished to prevent any security issues.
Devi Chand says
Hi,
My product images looked blurred because they are already optimised and wordpress was optimising them again (I believe). I used the above code and also regenerated the thumbnails. Initially, I could not find the changes. However, later the images started showing up the way I wanted (not blurred, perfect) for some time. But I check again and the images are all looking blurred again. Can you help?
Bjornen says
Hi!
So, is there a solution to having WP not up-scaling the image size (kb/mb) when uploading via “Media” in WordPress?
Meaning; I want WP to scale the picture into thumb nail, medium and large and to keep the original as it does per default, but NOT to up-scale the thumb ail, medium or large file sizes?
Thanks!
Mike says
I added this code exactly how you showed it and now it won’t let me upload photos an error message keeps coming up. please help! Thanks!
Yara says
Hi
Do you know if is possible to improve the quality of the image in wordpress.com in free version?
Thanks
Yara says
Or better, if is possible to do not reduce the quality of the image
WPBeginner Support says
Hi Yara,
You are limited to how WordPress.com handles images. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
Yara says
Hi
Now I have wordpress.org because I was frustated with my images quality. But now it is worst. I did what your video say, but I still have problems.
I thought that was just upload the image and was OK. My head image and when I upload in the post the quality is not good.
I really don’t know what to do :/
Mélanie says
Hi, I use this code and regenerated all my images, but unfortunatly, the size of my image is the same. I use enfold theme and my WP version is 4.7.2. Did I miss a step?
Mélanie says
I forgot to say, I compressed to 75.
Luke Cavanagh says
Setting the level to 92 or 90 is fine, the default used to be 90 was was lowered down to 82.
Alessandro says
Hi, I have added the code as showed in the video but, nothing, WordPress keeps reducing the size of my images.
Any other option?
Thanks for your support
Alessandro
Lukas Priyambodo says
Quality 100 doesn’t always mean highest quality, because of JPEG algorithm and what kind of content of the image. Using SSIM, I sometimes found that quality 95 has better score than quality 100 or at least quality 95 has better filesize trade off compare to quality 100.
Jaime says
Hi there. Are you able to disable image compression if you have a free WordPress account? If so, where do I find my function’s php file?
WPBeginner Support says
Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Admin
M.Mairaj says
Thanks for sharing such a fantastic post about image Compression in WordPress. All the tips are really very very worthwhile.
Keep sharing
Regards
Mairaj
Peter says
Don’t follow this advice! I added this line of code in my functions.php file and now I get this message when loading my website!
Parse error: syntax error, unexpected T_STRING in /home/sittin11/public_html/wp-content/themes/Divi/core/functions.php on line 44
WPBeginner Support says
See our guide on how to fix syntax error in WordPress.
Admin
blogmann says
Thanks
I’m using plugin Imsanity, it has more settings
karl says
Let’s clear up some things.
1 – WP does not mess with your original uploaded file. The compression levels discussed are for WP generated images – the TN, Med, Large in your WP media settings.
2 – if you change the compression settings, WP does not reprocess all your current uploads. That’s why you run Regenerate Thumbnails.
3 – I will challenge any photographer to see the quality difference between 100 and 90 in a JPG. In rare cases, you may. But for 99% of images you’ll never tell.
4 – Depending on your theme and your media settings, yes, some smaller image sizes will be cropped from your orignal upload. It’s the nature of the beast. If your TN is square and you upload a horizontal phjoto, of course it will be cropped. Cropping your images BEFORE uploading – and using a proportion compatible with your theme layout – will net you fewer issues.
Santiago Gonzalez says
Thanks Karl, your comment was very helpfull to clear things up.
Thanks
chang hong says
hello, can you tellme why wp crop every image that i upload? how can i prevent it! thank you
Dave Porter says
Thanks for the article, very useful to know.
I’m interested in the comment about ‘make sure you regenerate your thumbnails’
If an image is uploaded at say 82%, regenerating the thumbnails does what?
And I assume that after changing the percentage, this is only going to be for new images?
I would guess any existing images would remain at the same quality, or does WordPress keep a copy of the original uploaded?
TIA, Dave
WPBeginner Support says
WordPress keeps a copy of the original file uploaded.
Admin
Michael says
Is it possible to disable image compression in WordPress?
The article has a headline saying so, but then it describes it as “least compression”, that is not disabling compression…just wondering it is possible to disable compression for uploaded pictures…
karl says
Setting compression to 100 IS disabling it.
Thomas says
Great Tips, thank you.
I have one more question: If I upload images to WP that are already compressed (say to 90%) – will they be compressed again (82% of 90% = 74.8%)?
Stephen says
Yes. The only exception is the image you upload is saved as is for future use.