# Set WebP and AVIF Image Quality

> Sets the compression quality WordPress uses when it creates WebP and AVIF images, separately from JPEG, so you can trade a little sharpness for much smaller files.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: webp, avif, image-quality
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/media-webp-avif-quality/

## Code

```php
// Quality from 1 (smallest) to 100 (best).
$wpide_webp_quality = 75;
$wpide_avif_quality = 60;

add_filter( 'wp_editor_set_quality', function ( $quality, $mime_type ) use ( $wpide_webp_quality, $wpide_avif_quality ) {
    if ( 'image/webp' === $mime_type ) {
        return $wpide_webp_quality;
    }
    if ( 'image/avif' === $mime_type ) {
        return $wpide_avif_quality;
    }
    return $quality;
}, 10, 2 );
```

## Notes

Applies to newly generated images only; regenerate thumbnails to update existing ones. WordPress's default is 86 for WebP.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Set WebP and AVIF Image Quality" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
