Have Camera Will Travel - Reviews & Tips HomepageHave Camera Will Travel - Reviews & Tips

David Coleman Photography

  • Reviews & Tips
  • GoPro
  • Lightroom
  • Places
  • Photos
  • Reviews
    • Nikon
    • Sony
    • Fujifilm
    • Ricoh
    • Cameras
    • Lenses
    • Sample Images
    • Travel Tripods
    • Adventure Cameras
    • 360°
  • GoPro
  • Memory Cards
  • Flash
  • Travel Tripods
  • Books
  • Social Media
    • Facebook
    • Instagram
    • YouTube
    • Twitter

How to Change WordPress’s Default JPG Compression

By default, Wordpress compresses the versions of images it creates at a JPG quality setting of 82 percent. Here's how you can change it.

Wordpress Compression Pixelate

Categories: Optimizing Images for Websites, Wordpress for Photographers
Tags: Wordpress tricks
Last updated about 3 months ago // Originally published about 4 years ago

By default, WordPress compresses the versions of images it creates at a JPG quality setting of 82 percent. Here’s how you can change it.

WordPress leaves the original images you upload untouched (unless you’ve used a plugin to specifically override this behavior). But when you add a new image to the media library it also creates extra derivative thumbnail versions that are used throughout the site. There are a few built-in image sizes that you can access and change by going to Settings > Media. They’re thumbnail size, medium size, and large size. It’s also possible to add more image sizes.

WordPress’s JPG compression setting only applies to those derivative thumbnail versions that are created when you upload images to the media library.

It’s also important to note that this is, in effect, a cumulative compression. What I mean by that is that you are most likely uploading an image that has already been compression, most likely a JPG. The compression setting in WordPress will apply another round of lossy compression when creating the derivative thumbnails. It is, in effect, double-dipping on the compression. And that’s why the default quality is so high–higher than is often necessary for posting on the web.

As of WordPress 4.5, WordPress uses a default compression setting of 82. Previous versions used a setting of 90.

Why Change WordPress’s JPG Quality Setting?

So why would you want to change the default JPG compression setting? There are several possible reasons:

  • The cumulative compression might be resulting in images that aren’t as sharp as you’d like. So you can increase the quality setting if you like, or even turn it off.
  • You might want to make the compression more aggressive to create smaller filesizes. After all, smaller filesizes, especially with data-heavy information like images, can significantly increase your pagespeed. You might find you’re quite happy with the image quality at a setting of 70, in which case you’ll get even smaller filesizes that make for a faster website that in turn make your site’s visitors and the search engines happy.
  • You might be applying image optimization with something like WP Smush or ShortPixel. If you’re using those services’ lossy options, you’re going to be applying yet another round of compression that might further degrade the image quality.

How to Customize WordPress’s JPG Compression

Setting the compression quality level is as simple as adding a single line of code to your functions.php file.

As always when tinkering with the functions.php, make a backup copy first. That way, if you end up with a white screen, you can simply replace the faulty edited version with the original. And if you’ve never edited your functions.php before, go into it known that it is possible to mess things up. The most common consequence of that is a white screen of death. Don’t panic–it hasn’t deleted anything. Just replace the edited functions.php with the safe backup version your created.

So here’s how to do it.

Add this single line of code to your function.php, changing the number to your desired setting. 100 means no compression (or as near no compression as makes no meaningful difference). It is, in effect, turning off the compression.

add_filter( 'jpeg_quality', create_function( '', 'return 100;' ) );

You can also turn this around the other direction and add more JPG compression. Simply change the quality setting, like this:

add_filter( 'jpeg_quality', create_function( '', 'return 65;' ) );

The smaller the number, the more compression will be applied. Because it’s lossy compression, discarding information does degrade the image quality, so check the results on several images to make sure you’re happy with the image quality that’s coming out.

What About Existing Images?

This compression setting only applies to new images that uploaded to your media library after you’ve changed the setting. It doesn’t apply to previous images.

But once you’re happy with the results of whatever setting you’ve chose, you can go back and regenerate those older derivative images. The easiest way is to use a plugin. Regenerate Thumbnails is probably the most popular and works well. There are also others.

Optimization?

If you really want to keep your images’ filesizes down, image optimization is nearly always a great idea. I’ve put together some reviews of image optimizers for WordPress.

They work alongside WordPress’s own JPG compression. WordPress handles the files created with the initial upload. The image optimizers then work on those files.

By David Coleman
Instagram: @havecamerawilltraveldc

Last updated on January 11, 2021

Categories: Optimizing Images for Websites, Wordpress for Photographers
Tags: Wordpress tricks

I may earn a commission for purchases using links on this page. Learn more.

News & Deals

With the holidays fast approaching, there’s some great deals on photography gear and services available. I’ve put together a roundup of Black Friday and Cyber Monday 2020 Photography Deals. It’s a running list as new deals are announced, so be sure to check back.

Canon announces new EOS Rebel T8i DSLR. Canon has announced their new T8i DSLR. 24MP APS-C cropped CMOS sensor, 4K24 video, and updated image processing and detection systems. It’s available for preorder from B&H Photo.

New Firmware for the Ricoh GR III. Ricoh has release firmware v1.31 for the GR III. Release notes are: “Corrected — When shooting with the multiple exposure, in rare cases the live view may not display correctly. Improved stability for general performance.” You can download it here.

New Canon 1D X Mark III Pro DSLR Announced. Canon has announced their new flagship model of pro DSLR, the 1D X Mark III. They’re sticking with a 20.1MP CMOS sensor, but it’s a new and improved version and boasts an incredible native ISO range of ISO 100 to ISO 102400 and an extended range that goes up to a jaw-dropping ISO 819200. With revamped autofocus, a new image processor, and all sorts of other bells and whistles, it’s no wonder that Canon is billing it as “The Ultimate EOS.”

New Manfrotto Pro Rugged Memory Cards. Manfrotto, an Italian probably best known for their tripods and studio accessories, has launched a new Pro Rugged range of high-end SD, microSD, and CompactFlash cards. While they don’t have a huge selection of sizes and speeds, the cards are aiming for very fast cards that can put up with rugged demands. For instance, they claim that their V90 rated SD cards can withstand three times the force (20kg / 45 lbs) of a regular SD card. I’ve ordered some to run through my speed tests.

New Sony Alpha a7 firmware released. A firmware update for the Sony a7R IV now lets you control external Sony flashes from the camera’s own menu system. Up to 15 flashes in five groups can be controlled via the camera. It also applies to the a7R III and a7 III.

Kinsta Wordpress Managed Hosting

Comments

  1. Nils says

    November 10, 2019 at 9:58 pm

    There is also a very good plugin called Imsanity which allows you edit the JPG compression quality. So people who do not want to edit the code (which will also be replaced if you update your theme – unless you use a child theme) can easily edit the compression. The plugin also has some other useful options and is completely free as far as I know.

    Reply
    • David says

      November 11, 2019 at 8:43 am

      Thanks for the tip!

      Reply
  2. Amaresh says

    August 9, 2017 at 1:35 pm

    Hi I am Amaresh. I runs a blog which I have opened recently. I have been using WP Smush which provided me a good web speed. But I am facing problem with logo. The theme I am using gave me max height 80px. So I made a photo 282×80 px in PNG formatt. But the logo image looks blur. Please tell me how to make logo so that it looks sharp…Thank You

    Reply
    • David says

      August 10, 2017 at 10:11 am

      It could be any number of things, but it’s probably not a result of Smush. Something to try is uploading a PNG that’s twice the size (564×160). If the issue is related to retina display, that might fix it. It would also be worth trying a JPG version. That probably won’t make much difference–a PNG should be ideal in most cases for a logo–but it can’t hurt to try in case there’s some weird handling of PNGs in the theme.

      Reply

Questions & Comments Cancel reply

You have to agree to the comment policy.

About Me

I take photos. I travel. I do it for a living. Seven continents. Dozens of countries. Up mountains. Under water. And a bunch of places in between.

Get in Touch

Newsletter

© 2009–2021 David Coleman · Have Camera Will Travel LLC · all rights reserved


Photos by David Coleman. Please contact me for licensing images.
All images are registered with the U.S. Copyright Office.


Privacy & Disclosure · Cookie Declaration · Disclaimer · Terms of Service · Copyright · Contact


XML Sitemap