Reference: How to Upload Additional File Types in WordPress (by Antonio Villegas)
WordPress only allows file uploading into the media library if such files meet certain conditions.
If you do not want to limit the file types and thus upload any file into the media library, the easiest way to follow is to add the following line in the wp-config.php file:
define('ALLOW_UNFILTERED_UPLOADS', true );
If you want to solve the problem of uploading additional file types to WordPress, but being selective and only allowing a controlled subset of file types, then in functions.php:
add_filter( 'upload_mimes', 'my_myme_types', 1, 1 );
function my_myme_types( $mime_types ) {
$mime_types['svg'] = 'image/svg+xml'; // Adding .svg extension
$mime_types['json'] = 'application/json'; // Adding .json extension
unset( $mime_types['xls'] ); // Remove .xls extension
unset( $mime_types['xlsx'] ); // Remove .xlsx extension
return $mime_types;
}
To get the supported mime types, run this command:
wp_get_mime_types()
Retrieve list of mime types and file extensions.
