# Disabling automatic JPEG compression in WordPress using PHP

> Stop WordPress from compressing uploaded JPEG images by setting the quality to 100 with a short PHP snippet.

Source: https://helpcenter.ruachost.com/wordpress/guides/disabling-automatic-jpeg-compression-in-wordpress-using-php/

By default, WordPress automatically compresses JPEG images to **90% quality** when you upload them. While this helps reduce file size, it can noticeably lower image quality—especially if the image was already optimized before upload. On **ruachost.com**, you can disable this automatic compression using a simple PHP snippet.

## Why Disable JPEG Compression?

- Preserve original image quality.
- Prevent double compression of already optimized images.
- Ensure sharper visuals for photography or design‑focused sites.

## Steps to Disable JPEG Compression

1. **Log in to WordPress** with an administrator account.
2. In the dashboard, go to **Appearance → Theme Editor**.
3. Select your active theme and open the **functions.php** file.
4. Add the following code snippet at the end of the file:

   ```
   // Disable automatic JPEG compression in WordPress
   add_filter('jpeg_quality', function($arg){ return 100; });
   ```

   - `100` ensures images are saved at full quality.
   - You can adjust the value (0–100) if you prefer a custom compression level.
5. Save the file.
6. Upload a new JPEG image → WordPress will now keep it at the specified quality.

## Important Notes

- Always back up your theme before editing `functions.php`.
- Use a **child theme** to preserve changes during updates.
- This change only affects **new uploads**. Existing images remain compressed.
- To re‑apply settings to old images, use the **Regenerate Thumbnails plugin**.
