GET IN TOUCH WITH US: +353 (0)61 514582 info@darvu.com

Adding an upload filetype to WordPress

July 19th, 2012

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!

[code]
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’);
[/code]

Next Post: Sort listboxes that have been populated with JSON results.
Get In Touch

Have a query? Fill out the form below and we’ll get back to you as soon as possible.