Home » Hooks » upload_mimes

The "upload_mimes" hook is a filter that allows developers to add or remove MIME types that are allowed for file uploads in WordPress. MIME types are used to identify the type of file being uploaded (such as image/jpeg, video/mp4, application/pdf, etc.). By default, WordPress allows only a limited set of MIME types to be uploaded for security reasons. However, there may be cases where you need to allow additional MIME types that are not supported by default.

This hook can be used to modify the allowed MIME types for uploads. Developers can add new MIME types to the allowed list or remove existing ones. This can be useful in scenarios where you need to upload a file with a non-standard MIME type, such as a custom file format or a file type that is not recognized by WordPress.

Here’s an example of how you can use the "upload_mimes" hook to add a new MIME type to the list of allowed file types:

function custom_upload_mimes( $existing_mimes ) {
    // Add support for SVG files
    $existing_mimes['svg'] = 'image/svg+xml';
    return $existing_mimes;
add_filter( 'upload_mimes', 'custom_upload_mimes' );

In the example above, we’re adding support for SVG files by adding the "svg" MIME type to the list of allowed file types. The MIME type for SVG files is "image/svg+xml". By returning the modified array of MIME types using the "upload_mimes" filter, we’re telling WordPress to allow SVG files to be uploaded.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.