Menu Close

How to Add Additional File Types to be Uploaded in WordPress

default

Due to security reasons, WordPress only allows you to upload the most commonly used file types. By default, you can upload commonly used image formats, audio/video and documents using the default media uploader. But what if you wanted to upload a file type that is not allowed? In this article, we will show you how to add additional file types to be uploaded in WordPress.

If the above error looks familiar to you, then you’re at the right place.

File Types Allowed for Upload 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 bit of code, you can add a new file type and extension to 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:-


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.

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


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);

Awesome, now you can upload as many different file types as you like!

One other issue you may encounter is that you get a warning saying that the file “exceeds the maximum upload size for this site” as shown below:-

To resolve this issue please see the following article; WordPress troubleshooting guide to fix it.

If you need help with anything WordPress related, just drop me an email at nathan@silvawebdesigns.com or leave a comment below.

View Source
Posted in WordPress