upload_mimes
Filters which file types users can upload to the Media Library. Add an extension or remove one you don't want.
When it fires
WordPress applies upload_mimes in get_allowed_mime_types() whenever it needs the list of allowed file types, most importantly when a file is uploaded. The list maps file extensions to MIME types, for example 'jpg|jpeg|jpe' => 'image/jpeg'.
The second parameter tells you which user is being checked, or is null for the current user.
Parameters
$tarray |
Mime types keyed by the file extension regex corresponding to those types. |
|---|---|
$userint|WP_User|null |
User ID, User object or null if not provided (indicates current user). |
What to return
The array of allowed types, keyed by extension.
Example: Allow EPUB e-book uploads
add_filter( 'upload_mimes', function ( $mimes ) {
$mimes['epub'] = 'application/epub+zip';
return $mimes;
} );
Good to know
- WordPress also checks the real contents of the file. If they don't match the type you allowed, the upload is still refused.
- Don't allow SVG this way: SVG files can contain scripts. Use a plugin that sanitises them.
- On multisite, the network's 'Upload file types' setting also limits this list.