Allow or Restrict File Uploads by MIME Type


I recently experienced an issue where the network settings for allowing/disallowing certain file types (MIME types) didn’t work on one of my sites. So I set about writing the function below using the upload_mimes filter to manually edit the permitted MIME types on a specific site.

You can use it to add allowed MIME types (see line 2), or restrict certain MIME types (see line 3). Then you can just repeat the line as many times as you need to achieve the desired configuration.

This snippet should go in your functionality plugin.

Leave a Reply