WordPress Wednesday: Uploading More MIME Types to the Media Library

Geek Factor: 3

In this week’s WordPress Wednesday, we’re going to cover how to change the file types that you can upload to WordPress’s media library, allowing the addition of some file types that WordPress does not allow by default (like .eps files), or the restriction of file types that can be uploaded.

Extending and Limiting MIME Types with Plugins

The Manage Upload Types plugin gives site administrators the ability to view and edit the list of file types that can be uploaded to the Media Library. It is possible to add additional files with this plugin, as well as remove any of the default file types.

There is also a plugin developed specifically for WordPress MultiSite called AP Extend MIME Types that allows you to set allowed MIME types on a site-by-site basis.

WP Engineer also has a very simple plugin, Restrict MIME Type, that can just be used to restrict the file types that users can upload.

Extending and Limiting MIME Types Through Functions.php

The MIME types that can be uploaded to the Media Library can also be changed in your theme’s functions.php file. Just remember, any changes made to the functions.php file will only be applied to the theme you are using; if the theme is changed, these edits will need to be moved over.

In the below example, we’ll be adding the ability to upload .eps files to WordPress:

[php] // create and apply function to add mime types add_filter('upload_mimes', 'custom_upload_mimes'); function custom_upload_mimes ( $existing_mimes=array() ) { // Allows .eps files to be uploaded $existing_mimes['eps'] = 'application/postscript'; } [/php]

You can find an extensive list of MIME types and their extensions here.

Limiting MIME types can also be done using this code snippet from WPSnipp.com:

[php] add_filter('upload_mimes','restrict_mime'); function restrict_mime($mimes) { $mimes = array( // Lists the allowed MIME types; all others are excluded 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', ); return $mimes; } [/php]

Does anyone else have a good solution to changing WordPress’s default MIME types? Please share in the comments!

  1. Henry said:

    I tried the code snippers recommended but still got the same error message that EPS files were not allowed for security reasons. However, I found the plugin Manage Upload Types solved the problem completely without having to get into code any further.

    @ 7:19 am

Leave a Comment

Note: Fields marked with a * are required; email addresses are not published.

Legal FAQ Collections