WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Change WordPress JPEG Image Compression

How to Change WordPress JPEG Image Compression

Last updated on June 2nd, 2016 by Editorial Staff
389 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Change WordPress JPEG Image Compression

By default, WordPress compresses your images for better performance. Recently one of our readers asked if it was possible to change the image compression setting in WordPress. In this article, we will show you how to increase or decrease JPEG image compression in WordPress.

Every time you upload a JPEG image in WordPress, it would automatically compress the image to 90% quality. 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.

Subscribe to WPBeginner

However if you just want to follow text-instructions, then you can follow our step by step tutorial on how change WordPress JPEG image compression in WordPress.

How to Disable Image Compression in WordPress

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

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

When you set the value to 100, it means that WordPress compress the image at its highest quality.

If you’re 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 do make these image quality changes, you want to make sure that you regenerate your thumbnails.

We hope this article helped you learn how to change JPEG image compression in WordPress. If you’re a photographer, then you may want to check out Envira Gallery and the supersize add-on that allows you to display full-quality images on fullscreen view.

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.

389 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

42 Comments

Leave a Reply
  1. rob says:
    Oct 20, 2020 at 12:47 pm

    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

    Reply
    • WPBeginner Support says:
      Oct 21, 2020 at 9:41 am

      This would only apply to new images and not your current images and you do not have to worry about PNG compression.

      Reply
  2. Netgoondoo says:
    May 15, 2020 at 12:26 pm

    Hi, is this code snippet valid in php 7?

    Reply
    • WPBeginner Support says:
      May 18, 2020 at 3:36 pm

      The snippet should still be working

      Reply
  3. puspa chaulagai says:
    Apr 21, 2020 at 8:19 am

    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.

    Reply
    • WPBeginner Support says:
      Apr 22, 2020 at 11:04 am

      You would want to reach out to the support for your specific theme for them to be able to assist with their specific compression.

      Reply
  4. Sukanya says:
    Sep 4, 2018 at 9:48 am

    I have not seen much of a difference even after regenerating. Am I missing something?

    Reply
  5. Heather Wilson says:
    Apr 21, 2018 at 1:49 pm

    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.

    Reply
    • WPBeginner Support says:
      Apr 21, 2018 at 7:56 pm

      Hi Heather,

      No, you cannot. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.

      Reply
  6. Karlo Gavric says:
    Feb 10, 2018 at 11:10 am

    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?

    Reply
    • WPBeginner Support says:
      Feb 12, 2018 at 4:15 pm

      Hi Karlo,

      Try deactivating all plugins and switching to a default theme, after that upload a large image and see if that fixes it.

      Reply
      • Karlo Gavric says:
        Feb 16, 2018 at 7:38 pm

        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 ?!)

        Reply
        • nospampls says:
          Apr 1, 2019 at 8:45 am

          you need to set your large file size to a higher image size. wordpress will automatically crop your images…

  7. Anne says:
    Jan 23, 2018 at 4:42 pm

    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

    Reply
    • Eoin says:
      Mar 21, 2019 at 10:36 am

      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.

      Reply
  8. Devi Chand says:
    Jan 19, 2018 at 1:21 am

    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?

    Reply
  9. Bjornen says:
    Oct 29, 2017 at 5:06 am

    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!

    Reply
  10. Mike says:
    Aug 4, 2017 at 11:29 am

    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!

    Reply
  11. Yara says:
    Jun 24, 2017 at 9:53 am

    Hi

    Do you know if is possible to improve the quality of the image in wordpress.com in free version?

    Thanks

    Reply
    • Yara says:
      Jun 24, 2017 at 9:58 am

      Or better, if is possible to do not reduce the quality of the image

      Reply
    • WPBeginner Support says:
      Jun 26, 2017 at 3:58 am

      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.

      Reply
      • Yara says:
        Aug 3, 2017 at 8:29 pm

        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 :/

        Reply
  12. Mélanie says:
    Mar 6, 2017 at 11:03 am

    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?

    Reply
    • Mélanie says:
      Mar 6, 2017 at 11:06 am

      I forgot to say, I compressed to 75.

      Reply
  13. Luke Cavanagh says:
    Feb 3, 2017 at 2:01 pm

    Setting the level to 92 or 90 is fine, the default used to be 90 was was lowered down to 82.

    Reply
  14. Alessandro says:
    Nov 3, 2016 at 8:18 pm

    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

    Reply
  15. Lukas Priyambodo says:
    May 19, 2016 at 3:45 am

    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.

    Reply
  16. Jaime says:
    May 17, 2016 at 7:28 am

    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?

    Reply
    • WPBeginner Support says:
      May 18, 2016 at 2:35 am

      Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.

      Reply
  17. M.Mairaj says:
    May 9, 2016 at 12:50 am

    Thanks for sharing such a fantastic post about image Compression in WordPress. All the tips are really very very worthwhile.

    Keep sharing :)

    Regards

    Mairaj

    Reply
  18. Peter says:
    Apr 30, 2016 at 7:27 pm

    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

    Reply
    • WPBeginner Support says:
      May 1, 2016 at 6:03 pm

      See our guide on how to fix syntax error in WordPress.

      Reply
  19. blogmann says:
    Apr 26, 2016 at 2:34 am

    Thanks
    I’m using plugin Imsanity, it has more settings

    Reply
  20. karl says:
    Apr 25, 2016 at 10:18 am

    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.

    Reply
    • Santiago Gonzalez says:
      Oct 21, 2017 at 10:23 am

      Thanks Karl, your comment was very helpfull to clear things up.

      Thanks ;)

      Reply
  21. chang hong says:
    Apr 19, 2016 at 4:36 am

    hello, can you tellme why wp crop every image that i upload? how can i prevent it! thank you

    Reply
  22. Dave Porter says:
    Apr 18, 2016 at 9:15 pm

    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

    Reply
    • WPBeginner Support says:
      Apr 19, 2016 at 12:16 pm

      WordPress keeps a copy of the original file uploaded.

      Reply
  23. Michael says:
    Apr 18, 2016 at 12:35 pm

    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…

    Reply
    • karl says:
      Apr 25, 2016 at 10:11 am

      Setting compression to 100 IS disabling it.

      Reply
  24. Thomas says:
    Apr 18, 2016 at 12:01 pm

    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%)?

    Reply
    • Stephen says:
      Apr 26, 2016 at 10:30 am

      Yes. The only exception is the image you upload is saved as is for future use.

      Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
WP Mail SMTP logo
WP Mail SMTP
Fix WordPress email delivery issues. #1 SMTP plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
SeedProd Logo
SeedProd Coupon
Get 50% OFF SeedProd Coming Soon Page plugin for WordPress.
Cozmoslabs
Cozmoslabs Coupon
Get 15% OFF on Cozmoslabs WordPress premium plugins.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.