# Save JPEG and PNG Uploads as WebP

> Makes WordPress generate WebP versions instead of JPEG and PNG for every image size it creates on upload, which usually cuts image weight by a quarter or more.

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

## Code

```php
// Output format for resized images: image/webp or image/avif.
$wpide_output_format = 'image/webp';

add_filter( 'image_editor_output_format', function ( $formats ) use ( $wpide_output_format ) {
    static $checking = false;

    if ( $checking ) {
        return $formats;
    }

    $checking  = true;
    $supported = wp_image_editor_supports( array( 'mime_type' => $wpide_output_format ) );
    $checking  = false;

    if ( $supported ) {
        $formats['image/jpeg'] = $wpide_output_format;
        $formats['image/png']  = $wpide_output_format;
    }

    return $formats;
} );
```

## Notes

Needs a server whose GD or Imagick supports WebP; otherwise nothing changes. The original upload stays in its first format. Set the format to image/avif for AVIF.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Save JPEG and PNG Uploads as WebP" 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/
