Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Increase or Decrease WordPress JPEG Image Compression

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Increase or Decrease WordPress JPEG Image Compression

One of our users, a photographer, complained that the JPEG image he uploaded were losing a little bit of quality. After doing some research, we found out that it is true that WordPress does automatically compress JPEG images at 90% quality. In this article, we will show you how to increase or decrease WordPress JPEG image compression.

All you need to do is paste the following code in your theme’s functions.php file or your site-specific plugin.

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

Setting it to 100 would mean that WordPress would compress the image at its highest quality. For most users, this is not an issue. Heck, we never noticed it on our site. But if you are a photographer, then this is noticeable (we suppose).

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.

Source: Glyn Mooney

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Henry says:

    I’d try to use PHP with ImageMagick over GD.

    I could see some improvements in the quality of images resized by WordPress after I switched from GD to ImageMagick and changed the PHP settings to use it instead.

    This is especially useful for websites showing high quality photos or photography websites. You can see a live example here

  2. Shane says:

    The original will generally always be untouched unless you are using something like Imsanity to limit the max image resolution. The resized versions are where you will see the difference.
    Additionally, the quality setting is not linear, it is more exponential (or possibly logarithmic) Above 90, the quality gains are diminishing, while the file size begins to increase more and more with each increase of the quality setting. Even at 100, it will not be pixel perfect, because jpg is by definition a lossy format, but it will be much more difficult to distinguish the difference.

  3. Adam Freedman says:

    I’ve tried out this code, but there is no difference in quality between 90-100! To verify, I set the quality down to 20% and the thumbnails became really pixelated and blurry. So how come going from 90 to 100% doesn’t make any difference? I examined them very thoroughly and they look exactly the same….

  4. Mattia Frigeri says:

    I have tried various uploads… It seems to me that WP doesn’t reduce the image, the loaded one and the original one are exactly the same. I have also tried to write in functions.php this:

    add_filter(‘jpeg_quality’, function($arg){return 50;});

    nothing happened when I loaded a new image: same size again.


  5. VHamilton says:

    My site would not open after entering this code. I removed it. There have been other sites that have given “edit code” information that crashed my site. That is frustrating!

  6. Michael Bailey says:

    Thanks for this, just what I needed.


  7. Jose Vega says:

    Hi, i want to know if I can config wordpress to compress all types of images, not only jpeg. is it possible?

  8. Matt says:

    Hi there, i’m using Twitter Bootstrap for WordPress and when I add this code ‘add_filter(‘jpeg_quality’, function($arg){return 100;});’ into the theme it says there’s an error. What could I be doing wrong?

  9. Mattia Frigeri says:

    Works with php 5.3 or newer. For older versions you should use:

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

    as the reference says:

    • Lee Stuttaford says:

      Hi, just noticed a small issue :

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

      should be :

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

      or rather : in beginning of function array, what looks like 2x single > ‘ ” <

      Tricky to spot and will cause your functions file to die …

      • WPBeginner Support says:

        Please take a look at the article above. The actual line that we recommended is:

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

  10. Hubert Souchaud Mesmin says:

    How to change JPEG images quality with different value of % for the different auto-generated image sizes (ex full->90%, thumb->60%)? Thanks!

  11. siddharth sagar says:

    its great knowledge concerns…..thanks for it.
    before using this code, i face some problem about the layout of images………
    now its good…

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.