Disable Automatic Compression of JPG in WordPress

How to Disable Automatic Compression of JPG in WordPress

in Optimization & Best Practice
Google+ LinkedIn

WordPress has built in compression for JPG images. Whenever you upload an JPG/JPEG image to WordPress media library, WordPress will automatically compress your images to 90% of the original quality, this is intended to help your pages load faster and keep file sizes smaller.

But sometime it’s essential to have high quality images on your website. For example if you are a photographer or have a portfolio website, then it’s very important that you must always have the highest quality images on your website.

If having best quality images on your website is absolutely necessary for you too, then you can disable automatic compression of JPG in WordPress by changing the default JPG compression to 100% and tell WordPress to load these file at their original quality.

All you have to add the following code snippet to your functions.php file, this will run when compressing your images and return the value of the quality you want.

// set minimum word count to publish post
function wcs_disable_image_compression( $arg ) {
    return 100;
}
add_filter( 'jpeg_quality', 'wcs_disable_image_compression' );
add_filter( 'wp_editor_set_quality', 'wcs_disable_image_compression' );

Share the love

If you like this snippet, share it with others!

2 Replies on "Disable Automatic Compression of JPG in WordPress"

  1. Hamad

    Ok Vanessa…
    Can I use a plugin for this?

    thanks

    1. Yes, you can use a plugin but why do you need a plugin when you can add these 4 lines in your theme and be done with it.

      It’s not like plugin will offer any great features. The code will remain the same either you use a plugin or not.

Leave a Reply

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