Enabling vCard Uploads in WordPress with upload_mimes Hook


If you need to allow vCard file uploads to your WordPress site, you can use the upload_mimes hook to add vCard file formats to your list of allowed mime types. In this blog post, we’ll show you how to use this hook and provide a code example that you can use in your custom or child theme’s functions.php file or in a custom plugin.

Adding vCard File Formats to Your Allowed Mime Types

/**
 * Enable vcard upload
 */
function enable_vcard_upload( $mime_types = array() ) {
	$mime_types['vcf']   = 'text/vcard';
	$mime_types['vcard'] = 'text/vcard';

	return $mime_types;
}
add_filter( 'upload_mimes', 'enable_vcard_upload' );

You can modify this function to add other file formats, but be careful not to add file types that could open up security holes on your site. For example, you should use the Safe SVG plugin to safely allow SVG uploads.

Examples of vCards can be found here. These include formats not included in the code example above.


By:

Published:

Category:

Tags:


One response to “Enabling vCard Uploads in WordPress with upload_mimes Hook”

  1. kmelen Avatar

    This worked! Thank you.

Leave a Reply

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

%d bloggers like this: