Adding an upload filetype to WordPress

By default, wordpress limits the files types that you are allowed to upload to images, pdf files, and a few others (full list of allowed file types here). When you try to upload a filetype that isn’t on that list of allowed types, you will get a File type does not meet security guidelines. Try another. error. Not to fear, this is easy to get around by adding the code below to your theme functions.php file.

This quick snippet will allow you to add multiple new filetypes to the allowed list (in this example, I have added .bib and .txt files to the list of allowed filetypes. To add additional filetypes, simply modify the third line below, placing a “|” between your new types. Simple!

function addUploadFileTypeMimes($mimes) {
    $mimes = array_merge($mimes, array(
            'bib|txt' => 'application/octet-stream'
        )); //join the default upload mime types and your custom type list.

    return $mimes;
}

add_filter('upload_mimes', 'addUploadFileTypeMimes');

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.