Skip to content

Instantly share code, notes, and snippets.

@paolo-mnet
Last active June 6, 2022 12:42
Show Gist options
  • Save paolo-mnet/b588b8d7d9ccf4b1e68a4af8b8c9b3f7 to your computer and use it in GitHub Desktop.
Save paolo-mnet/b588b8d7d9ccf4b1e68a4af8b8c9b3f7 to your computer and use it in GitHub Desktop.
WordPress: Allow upload of non-standard file types in the media library.
<?php
// functions.php
/**
* Allow upload of non-standard file types in the media library.
*
* @param array $mime_types [default mime types].
* @return array $mime_types [modified mime types].
*/
function mnet_upload_mime_types($mime_types) {
if ( !isset($mime_types['webp']) ) {
$mime_types['webp'] = 'image/webp';
}
if ( !isset($mime_types['svg']) && current_user_can('edit_posts') ) {
$mime_types['svg'] = 'image/svg+xml';
}
return $mime_types;
}
add_filter('upload_mimes', 'mnet_upload_mime_types', 110, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment