Rabbit

Tutorials

How to add and remove MIME types in WordPress

The filename suffixes used in Windows are meaningless in Linux; instead, MIME types are used to convey type information when transferring documents over the Internet.

The following will output the list of MIME types allowed by default in WordPress.

$mime_types = get_allowed_mime_types();
print_r( $mime_types );

To remove MIME types from the list, we can use the upload_mimes filter.

add_filter( 'upload_mimes', function( $mime_types ) {
    // Remove the zip and tar types.
    unset( $mime_types['zip'], $mime_types['tar'] );
    return $mime_types;
} );

To add MIME types to the list, we can use the mime_types filter.

add_filter( 'mime_types', function( $mime_types ) {
    // Add the zip and tar types.
    $mime_types = array_merge(
        $mime_types,
        array(
            'zip' => 'application/zip',
            'tar' => 'application/x-tar'
        )
    );
    return $mime_types;
} );

Posted by on .

0 comments

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>