2. Add File Types to Media Library

2. Add File Types to Media Library

File Types Allowed for Upload in WordPress

https://www.wpbeginner.com/wp-tutorials/how-to-add-additional-file-types-to-be-uploaded-in-wordpress/

WordPress allows you to upload most common image files, audio/ video, PDF, Microsoft office and OpenOffice documents. WordPress codex has a full list of allowed file types and extensions.

Adding Exceptions for Additional File Types

Security is the main reason behind the limitation on file types that users can upload. However, this does not mean that users cannot change this. Using a tiny bit of code, you can add a new file type and extension to the WordPress.

For example, add this code in your theme’s functions.php file or a site-specific plugin to allow SVG file type to be uploaded:

1
2
3
4
5
function my_myme_types($mime_types){
    $mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

Notice that the file extension goes as the key in $mime_types associated array and the mime type goes as its value.

In this example, svg file extension represents files with the mime type image/svg+xml. You can find out mime types of several common file extensions on this page.

https://www.freeformatter.com/mime-types-list.html

You can also add multiple file types in one code snippet, like this:

1
2
3
4
5
6
function my_myme_types($mime_types){
    $mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
    $mime_types['psd'] = 'image/vnd.adobe.photoshop'; //Adding photoshop files
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

*** End of Content ***

Last Update: 02/06/2020