How To Add A vCard Download To A WordPress Site

vcardRecently a client asked us if we would add links to their staff’s vCards to the WordPress site that we had just designed and developed for them. We had never done it before, but it didn’t seem like a big deal. In the words of Indiana Jones—“How hard can it be?” We’ll just add the vCards to the Media Library and link to them.

We soon found a fix that wasn’t a hack and didn’t involve a plugin, but, in our case, it required several steps and there was no one place on the internet (well, we couldn’t find one) that mentioned all the steps in one article. So we decided to write one.

Step One

The first thing we found was that you cannot upload vCards (.vcf files) to the WordPress Media Library. WordPress only allows certain file types to be uploaded and .vcf is not one of them. Regardless of the method used trying to upload a vCard results in the error message “This file type is not allowed. Please try another.”

After a little research we found that by adding some code to a theme’s functions.php file we could add functionality that would support uploading a .vcf file. We added the following code to the functions.php file:

// Allow .vcf files to upload to the media library
 add_filter('upload_mimes', 'custom_upload_mimes');
 function custom_upload_mimes ( $existing_mimes=array() ){
 // add your extension to the array
 $existing_mimes['vcf'] = 'text/x-vcard'; return $existing_mimes;

It worked, but not as we expected.

Step Two

In some situations, if you click on a link to a .vcf file, the vCard isn’t downloaded. Instead its contents are displayed in the browser window as text. We found that in order to force these files to download correctly we needed to make changes to the site’s .htaccess file.

We added the code line below to the site’s .htaccess file. (If you can’t find your site’s .htaccess file click on the link in the paragraph above for help.)

AddType text/x-vcard .vcf

It didn’t work.

Step Three

Refresh you browser. As simple as it is if you don’t do this stuff every day it’s easy to forget the power of a browser refresh.

After a browser refresh everything worked as expected. We are now able to upload a .vcf file to WordPress, and visitors to the site are able to download them.