Skip to content

Snippet: Allow SVG Uploads in WordPress

By default SVG files are not allowed in WordPress for security reasons so they can't be uploaded, however you can hook into the "upload_mimes" filter to add support for svg file types. This snippet has an extra security check in place so that only site admins can upload SVG's but as always if you are going to upload SVG files to your site make sure to review the file code to ensure there isn't anything malicious before uploading it.

But before you go adding any code to your site we would highly recommend you instead use the Safe SVG plugin, especially if you are working with a client site.

 * Allow SVG uploads.
 * @link
add_filter( 'upload_mimes', function( $mimes = array() ) {
	if ( current_user_can( 'administrator' ) ) {
		$mimes['svg'] = 'image/svg+xml';
		$mimes['svgz'] = 'image/svg+xml';
	return $mimes;
}, 99 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top