Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

upload_mimes

Filters which file types users can upload to the Media Library. Add an extension or remove one you don't want.

  • Type Filter
  • From WordPress
  • Since 2.0.0
  • Fired in wp-includes/functions.php

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

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

PHP
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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.