Family Encyclopedia >> Electronics

How to Safely Add Custom File Types to WordPress Uploads: A Step-by-Step Guide

As WordPress security experts with years of hands-on experience, we've helped countless sites expand upload capabilities while maintaining robust protection. By default, WordPress restricts uploads to common image, audio/video, and document formats for security. But if you need to allow additional types like SVG files, we'll show you how to do it safely using code.

How to Safely Add Custom File Types to WordPress Uploads: A Step-by-Step Guide

Video Walkthrough

Subscribe to WPBeginner for our video tutorial. If you prefer reading, continue below.

Default File Types Allowed in WordPress

WordPress supports uploads of popular images, audio/video files, PDFs, Microsoft Office, and OpenOffice documents. Check the official WordPress Codex for the complete list of allowed extensions and MIME types.

Adding Support for Custom File Types

Security is paramount, which is why uploads are limited—but you can extend them responsibly with a custom function. Add this code to your theme's functions.php file or a site-specific plugin to enable SVG uploads:

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

The file extension serves as the array key, with the corresponding MIME type as its value. For SVG, it's image/svg+xml. Reference this IANA MIME types list for others.

To add multiple types at once, like SVG and PSD:

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

How to Safely Add Custom File Types to WordPress Uploads: A Step-by-Step Guide

This approach has empowered our clients to handle specialized files without compromising security. We also recommend reviewing how to increase maximum file upload size.

Enjoyed this? Subscribe to our WordPress YouTube Channel for more tutorials. Follow us on Twitter and Google+.