Allow New MIME Types in WordPress Uploader

October 20, 2021
Code Category:

WordPress snippet lets you set new file types to upload into the Media section. This is specifically for SVG files, but you could add any file type you like if you know the MIME type.

Here's a list of MIME types: https://www.sitepoint.com/mime-types-complete-list/

/**
 * Allow the upload of different files types.
 * SVG is included in this example.
 */
function custom_mime_type_uploads( $mimes ) {
 
  // New allowed mime types.
  $mimes['svg'] = 'image/svg+xml';
  $mimes['svgz'] = 'image/svg+xml';
  $mimes['doc'] = 'application/msword';
   
  // Optional. Remove a mime type.
  //unset( $mimes['exe'] );
   
  return $mimes;
}
add_filter( 'upload_mimes', 'custom_mime_type_uploads' );

Thanks to:

©2022 Fotan Web Design