I'm attempting to perform some basic jpeg compression by using the jpeg_quality hook inside my functions.php file but there is no compression/resizing taking place. I'm only measuring file compression on jpegs added to the library after the functions.php file had been edited. Here is the code:

function custom_jpeg_quality($quality) {
   return 20;
add_filter('jpeg_quality', 'custom_jpeg_quality');

Thanks in advance to anyone who can assist.


WordPress uses that when it resizes images to set the quality, but it will not go back and resize images it's already processed. If it did, your site would be continuously checking your uploads and grind to a halt

You have these choices:

  • Delete your attachments and reupload them
  • Use a tool such as the regen thumbnails plugin to recreate the images ( will take some time )

These will only affect the image sizes, not the original image that was uploaded ( image size full )

  • Just to be clear, if I add a 5mb file to the library after editing the functions.php file, there will be no compression or resizing to that jpeg? – B6431 Jun 21 '16 at 13:29
  • If you upload a file, it's kept intact, and a series of images are generated for each image size. That is where the recompression happens. If you're uploading a 5MB jpeg, compression may fail for other reasons ( running out of time before the execution limit, especially on shared hosts ). You would be much better off testing with a smaller jpeg – Tom J Nowell Jun 21 '16 at 13:32
  • By image sizes, I mean the medium, small, thumbnail, etc, there is no 1 single jpeg – Tom J Nowell Jun 21 '16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.