apply_filters( 'upload_mimes', array $t, int|WP_User|null $user )

Filters the list of allowed mime types and file extensions.


$t array
Mime types keyed by the file extension regex corresponding to those types.
$user int|WP_User|null
User ID, User object or null if not provided (indicates current user).

Top ↑


File: wp-includes/functions.php. View all references

return apply_filters( 'upload_mimes', $t, $user );

Top ↑


Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Mahesh Waghmare

    Add MIME types.

    function my_custom_mime_types( $mimes ) {
    	// New allowed mime types.
    	$mimes['svg']  = 'image/svg+xml';
    	$mimes['svgz'] = 'image/svg+xml';
    	$mimes['doc']  = 'application/msword'; 
        // Optional. Remove a mime type.
        unset( $mimes['exe'] );
    	return $mimes;
    add_filter( 'upload_mimes', 'my_custom_mime_types' );
  2. Skip to note 2 content
    Contributed by Jb Audras

    (example taken from @dotmastaz’s feedback)
    Allow SVGZ mime type:

    function svgz_mime_types( $mimes ) {
            // SVGZ allowed mime types.
            $mimes['svgz'] = 'application/x-gzip';
            return $mimes;
    add_filter( 'upload_mimes', 'svgz_mime_types' );

    And if you want to know what is your real file mime type, you can use this service:

  3. Skip to note 3 content
    Contributed by Justin Kopepasah

    Filter the upload mime types to allow JSON files.

     * Allow JSON file uploads to WordPress media library.
     * Filters the uploads mime types to allow JSON files.
     * @param array $types Currently allowed types.
     * @return array Filtered types.
    	function( $types ) {
    		return array_merge( $types, array( 'json' => 'text/plain' ) );
  4. Skip to note 6 content
    // To upload photos in format WebP
    function wpdocs_custom_mime_types( $mimes ) {
    	// New allowed mime types.
    	$mimes['webp'] = 'image/webp';
    	return $mimes;
    add_filter( 'upload_mimes', 'wpdocs_custom_mime_types' );

    If you work locally, for example on XAMPP, you should also include extension=gd in php.ini, just uncomment it, removing ; in front of it.

You must log in before being able to contribute a note or feedback.