Home » Hooks » post_mime_types

The post_mime_types hook is a WordPress filter hook that allows developers to modify the list of MIME types associated with a post.

In WordPress, a MIME type is a way to classify different types of files. When a file is uploaded to the media library or attached to a post, it is assigned a MIME type based on its file extension. The post_mime_types hook provides a way to modify or add new MIME types to this list.

This hook is particularly useful when you want to extend the default list of supported file types in WordPress. For example, if you want to allow users to upload a new file type that is not supported by default, you can use the post_mime_types hook to add the MIME type for that file extension.

Here’s an example usage code that demonstrates how to use the post_mime_types hook to add a custom MIME type:

function custom_post_mime_types( $mime_types ) {
    $mime_types['my-custom-type'] = array(
        'label' => 'My Custom Type',
        'extensions' => array( 'myext' ),
        'type' => 'application/my-custom-type'
    return $mime_types;
add_filter( 'post_mime_types', 'custom_post_mime_types' );

In this example, we define a new custom MIME type "my-custom-type" with the label "My Custom Type" and the file extension "myext". We also specify the corresponding MIME type as "application/my-custom-type". By adding this code snippet to your theme’s functions.php file or a custom plugin, you can enable uploading and attaching files with the "myext" extension in WordPress.

Using the post_mime_types hook, you have the flexibility to customize the list of supported file types in WordPress, making it easier to manage and work with various file formats within your website.

Learn More on

WordPress snippets using the post_mime_types hook

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