search ]

How to Enable the Upload of Additional File Types in WordPress?

For security purposes, WordPress only allows uploading of common file types such as images, videos, and documents and such. But what should we do in a case where we want to upload files with extensions that WordPress doesn’t allow by default?

In this short guide, I will explain how to enable the upload of additional file types in WordPress. Let’s begin…

How to Enable Upload of Additional File Types?

Here is a link to the list of file types that WordPress allows to be uploaded by default. The main reason WordPress prevents the upload of all file types is security, as mentioned.

One way to change this behavior and allow the upload of additional files is by adding the code below to the functions.php file:

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
    $mime_types['webp'] = 'image/webp'; // WEBP Images
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

In the new versions of WordPress, it is possible to upload WEBP files without needing line 4 in the code.

In this case, we are allowing the upload of Photoshop (PSD) files, SVG files and WEBP images that we all prefer to use. If you want to add more file types, you need to know their MIME Type. A list of common MIME Types can be found in this link.

Another way, and perhaps even simpler, is to enable the upload of all file types without restriction. This can be done by adding the following line to the wp-config.php file:

define( 'ALLOW_UNFILTERED_UPLOADS', true );

The wp-config.php file allows you to modify the default behavior of WordPress. You will find this file in the root directory of the server (the directory where WordPress is usually installed).

How to Prevent the Upload of a Specific File Type?

If you want to remove a specific file type and prevent it from being uploaded, add the following code to the functions.php file:

function disallow_personal_uploads ( $existing_mimes=array() ) {
 
    // remove GIF files
    unset ($existing_mimes['gif']); 
 
    // return amended array
    return $existing_mimes;
}

// call our function when appropriate
add_filter('upload_mimes', 'disallow_personal_uploads');

This code snippet will block the option to upload gif files in WordPress. I hope this tip helps you. As always, feel free to comment and share…

0 Comments...

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development