Add Modern Image Formats to Network Upload Types
Adds WebP and AVIF to the file types every site on the network may upload, without editing the "Upload file types" list in Network Settings.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_extra = array( 'webp', 'avif' ); // Extensions to allow.
add_filter( 'site_option_upload_filetypes', function ( $types ) use ( $wpide_extra ) {
$list = array_filter( explode( ' ', strtolower( (string) $types ) ) );
return implode( ' ', array_unique( array_merge( $list, $wpide_extra ) ) );
} );
Notes
Add other extensions to $wpide_extra; the server must also allow their MIME types.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.