Change which type of files you can upload in WordPress

We recently had a client that needed to be able to upload a “vCard” and they were not able to do so. That is because WP limits what type of files can be uploaded. By default you can only upload media to the “Media Library”, which makes perfect sense, right? But what if we need to upload PowerPoint, Word documents, etc, well, here is the code that allows you to do that.

Go to the theme’s functions.php file and drop in the code (within the tags that should already be at the top of the file).
[cc lang=”html”]
add_filter(‘upload_mimes’, ‘custom_upload_mimes’);
function custom_upload_mimes ( $existing_mimes=array() ) {
$existing_mimes[‘vcard’] = ‘application/x-vcard’;
$existing_mimes[‘vcf’] = ‘application/x-vcf’;
return $existing_mimes;
}
[/cc]

photo credit: bs-iv-folie-2 via photopin (license)

About the Author

Picture of Aaron Reimann

Aaron Reimann

Aaron is a PHP developer who started and sold an agency called Sideways8.com. He is currently running Clockwork, a website design, development and hosting shop. He has built sites for companies of all shapes and sizes, ranging from small nonprofits to Fortune 100 companies, since beginning his work with WordPress in 2008. An organizer for WordCamp Atlanta and the Atlanta WordPress Meetup, Aaron provides leadership and speaks regularly at events around the world.
Picture of Aaron Reimann

Aaron Reimann

Aaron is a PHP developer who started and sold an agency called Sideways8.com. He is currently running Clockwork, a website design, development and hosting shop. He has built sites for companies of all shapes and sizes, ranging from small nonprofits to Fortune 100 companies, since beginning his work with WordPress in 2008. An organizer for WordCamp Atlanta and the Atlanta WordPress Meetup, Aaron provides leadership and speaks regularly at events around the world.