How to increase / decrease the compression of JPEG images in WordPress

Many of those involved in professional photography noticed that when downloading photos in WordPress lose some image quality.


After conducting some studies have found that this is true and WordPress automatically compresses the image quality of 90% of the original. This article will give a method to fix it.
All you need is to insert the following code into the theme functions.php or a plugin that you use on your website:

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

Setting to 100 means that WordPress will compress in the best quality possible. For many people, this is important, I do not use this trick on your site, but if you are a photographer then this information will be useful.
If on the contrary there is a desire to reduce this value you can also do this by changing the value to 80 for example, to increase the download speed.
Of course it would be interesting to find out how to change the compression quality of other images, not only JPEG, I hope to be soon.
Please note that the code will work in versions of WordPress 5.3 and newer, older versions should use the code:

add_filter( ‘jpeg_quality’, create_function( ”, ‘return 100;’ ) );



if you have questions about the article, you can ask them in the comments below.