Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/upload mimes

Upload Mimes Filter

This filter can be used to alter the list of acceptable file extensions WordPress checks during media uploads. Altering this list through the use of this filter can help you when you are presented with the "File type does not meet security guidelines. Try another." error message.

Example Usage

To make use of this filter, you will need to place a function similar to the below in your theme's functions.php file.

Firstly, add the following line of code to your theme's functions.php file to show WordPress that you want to hook in to this filter -

add_filter('upload_mimes', 'custom_upload_mimes');

The first parameter is the filter name, the second paramter is the name of the function that you are going to create to alter the list (so you can name this as you like, so long as it matches the name in this next piece of code.)

Now for the real work - your function. This adds or removes the file types -

function custom_upload_mimes ( $existing_mimes=array() ) {
// Add file extension 'extension' with mime type 'mime/type'
$existing_mimes['extension'] = 'mime/type';
// add as many as you like e.g. 

$existing_mimes['doc'] = 'application/msword'; 

// remove items here if desired ...
// and return the new full result
return $existing_mimes;


Should you wish to remove items from the list, you can use unset - e.g.

unset( $existing_mimes['exe'] );

Which you would place into the above function where the placeholder text "remove items here if desired" is.

This article is marked as in need of editing. You can help Codex by editing it.