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

Filters the list of allowed mime types and file extensions.


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


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



User Contributed Notes

  1. Skip to note 7 content

    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 8 content

    (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 9 content

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