Add & Remove Filetypes in WordPress Media Library

When trying to upload a file in WordPress, you might see the error message, “Sorry, this file type is not permitted for security reasons.”

By default, WordPress only allows you to upload certain filetypes. Most common filetypes for images & Microsoft Office documents are allowed (jump down to the full list). But let’s take a look at how to add additional filetypes in the WordPress Media Library. We’ll also cover removing filetypes, as well as take a quick look at filetypes for WordPress Multisite.

NOTE: Managing allowed filetypes in WordPress via a plugin: There are a few plugins in the WordPress repo, but they haven’t been updated in over 2 years, so I would not recommend using them.

First we’ll add filetypes, and then for more fine-grained control, we’ll show you how to remove them.

As with most functionality enhancements to WordPress, there are two places you could put this code:

  • a custom functionality plugin (recommended) -or-
  • your theme (or child theme’s) functions.php file

How to Add Allowed Filetypes to WordPress Media Library

Adding a single filetype looks like this:

function my_mime_types($mime_types){
    $mime_types['zip'] = 'application/zip';
    return $mime_types;
}
add_filter('upload_mimes', 'my_mime_types', 1, 1);

In this example, zip is the file extension and application/zip is the MIME type. Here’s a full list to help you find the MIME type for your file extension.

You can also add multiple filetypes:

function my_mime_types($mime_types){
    $mime_types['zip'] = 'application/zip';
    $mime_types['tiff'] = 'image/tiff';
    $mime_types['bmp'] = 'image/bmp';
    return $mime_types;
}
add_filter('upload_mimes', 'my_mime_types', 1, 1);

More about the upload_mimes filter on Codex »

How to Remove Filetypes from the WordPress Media Library

To remove default filetypes allowed by WordPress, we use the unset function.

function my_mime_types($mime_types){
    unset($mime_types['pdf']); // Removes the .pdf extension
    return $mime_types;
}
add_filter('upload_mimes', 'my_mime_types', 1, 1);

You can add & remove filetypes all in the same code block. Just list each filetype (addition or removal) on its own line.

Code Samples

Here’s a bunch of filetypes you might want to add, all compiled into one function. You can copy the whole thing & just delete what you don’t need. I’ve figured out all the MIME types for you already :-)

Please be careful allowing any type of executable or script. There is inherent risk with allowing these types of files.

function my_mime_types($mime_types){
    $mime_types['zip'] = 'application/zip';
    $mime_types['rar'] = 'application/x-rar-compressed';
    $mime_types['tar'] = 'application/x-tar';
    $mime_types['gz'] = 'application/x-gzip';
    $mime_types['gzip'] = 'application/x-gzip';
    $mime_types['tiff'] = 'image/tiff';
    $mime_types['tif'] = 'image/tiff';
    $mime_types['bmp'] = 'image/bmp';
    $mime_types['svg'] = 'image/svg+xml';
    $mime_types['psd'] = 'image/vnd.adobe.photoshop';
    $mime_types['ai'] = 'application/postscript';
    $mime_types['indd'] = 'application/x-indesign'; // not official, but might still work
    $mime_types['eps'] = 'application/postscript';
    $mime_types['rtf'] = 'application/rtf';
    $mime_types['txt'] = 'text/plain';
    $mime_types['wav'] = 'audio/x-wav';
    $mime_types['csv'] = 'text/csv';
    $mime_types['xml'] = 'application/xml';
    $mime_types['flv'] = 'video/x-flv';
    $mime_types['swf'] = 'application/x-shockwave-flash';
    $mime_types['vcf'] = 'text/x-vcard';
    $mime_types['html'] = 'text/html';
    $mime_types['htm'] = 'text/html';
    $mime_types['css'] = 'text/css';
    $mime_types['js'] = 'application/javascript';
    $mime_types['ico'] = 'image/x-icon';
    $mime_types['otf'] = 'application/x-font-otf';
    $mime_types['ttf'] = 'application/x-font-ttf';
    $mime_types['woff'] = 'application/x-font-woff';
    $mime_types['ics'] = 'text/calendar';
    return $mime_types;
}

add_filter('upload_mimes', 'my_mime_types', 1, 1);

Developers: To see WordPress’ full list of filetypes, open wp-includes/functions.php and search for “function wp_get_mime_types”.

List of WordPress Accepted Filetypes

Please note: Even though WordPress allows it, your web hosting company might not. If you cannot upload a file on this list, please contact your web host.

Images

  • .jpg, .jpeg
  • .png
  • .gif

Documents

  • .pdf (Adobe Acrobat Portable Document Format)
  • .doc, .docx (Microsoft Word Document)
  • .ppt, .pptx, .pps, .ppsx (Microsoft Powerpoint Presentation)
  • .xls, xlsx (Microsoft Excel Spreadsheet)
  • .odt (OpenDocument Text Document)

Audio

  • .mp3
  • .m4a
  • .ogg
  • .wav

Video

  • .mp4, .m4v (aka: MPEG-4)
  • .mov (QuickTime)
  • .wmv (Windows Media Video)
  • .avi
  • .mpg
  • .ogv (aka: Ogg)
  • .3gp (aka: 3GPP)
  • .3g2 (aka: 3GPP2)

See the WordPress Codex for the most current list.

WordPress Multisite Allowed Filetypes

Allowed filetypes for WordPress Multisite are a little different. Once you create Network, you can change the permitted filetypes from the Network Settings screen. This will globally allow or disallow certain files from being added to the WordPress Media Library.

Each filetype should be separated by a space. Just add or remove the filetypes you want to change. This will make the change for all users across your entire network (who have the capability to upload files). Here’s a list of the default allowed filetypes for WordPress Multisite:

  • jpg
  • jpeg
  • png
  • gif
  • mov
  • avi
  • mpg
  • 3gp
  • 3g2
  • midi
  • mid
  • pdf
  • doc
  • ppt
  • odt
  • pptx
  • docx
  • pps
  • ppsx
  • xls
  • xlsx
  • key
  • mp3
  • ogg
  • wma
  • m4a
  • wav
  • mp4
  • m4v
  • webm
  • ogv
  • wmv
  • flv

What Are Your Thoughts?

All fields are required. Your email will not be published.

You can use standard <code> and <pre> tags to post code examples, or a service like codepen.io.