Site icon Dhanendran's Blog

How to Upload Additional File Types in WordPress

It’s been always the case where we need to upload additional file types in WordPress along with the WordPress default supported file types.

By Default WordPress will allow you to upload below mentioned file types to media library.

Images

Documents

Audio

Video

But as mentioned this is not enough for our dream website. We need to have more file type support, so that we can do some cool stuffs right?

There are 2 ways to achieve this.

  1. Filters
  2. Wp-config.php

Filters

We need to use upload_mimes filter to add or remove the file types we need to support on the site. Have look at the below example, for adding and removing a file type.

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' );

wp-config.php

This is another way where we can allow any type of file to be uploaded in the WordPress media library. Open up the wp-config.php file and add the below line.

define( 'ALLOW_UNFILTERED_UPLOADS', true );

This will allow users to upload any type file to WordPress.

Conclusion

I would recommend to use the filters to change the file types supported by your site, as it will give you more control over the files. If we use wp-config.php method, then we can’t predict what type of file is being uploaded by the users and it may cause some major security issues.

Exit mobile version