Skip to content

Instantly share code, notes, and snippets.

@davidchc
Created July 10, 2020 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchc/f6372d6909b3ab346f31ab4898e9a30c to your computer and use it in GitHub Desktop.
Save davidchc/f6372d6909b3ab346f31ab4898e9a30c to your computer and use it in GitHub Desktop.
<?php
function add_file_and_ext_webp( $types, $file, $filename, $mimes ) {
if ( false !== strpos( $filename, '.webp' ) ) {
$types['ext'] = 'webp';
$types['type'] = 'image/webp';
}
return $types;
}
add_filter( 'wp_check_filetype_and_ext', 'add_file_and_ext_webp', 10, 4 );
function add_mime_types_webp( $mimes ) {
$mimes['webp'] = 'image/webp';
return $mimes;
}
add_filter( 'upload_mimes', 'add_mime_types_webp' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment