Allow SVG media images to be uploaded to WordPress

Allowing the uploading of SVG files to the WordPress media library through a simple snippet.


Out of the box, WordPress doesn’t allow the uploading of SVG files for security reasons. SVG images are essentially XML files which themselves are vulnerable to a variety of vulnerabilities. However, if you need to allow the uploading of SVG files to your media library through the WordPress admin, you can do so by adding this simple snippet to your functions.php file or an equivalent.


/*
 * Allow SVG images to be uploaded to the media library
 */

function cc_mime_types($mimes) {
  $mimes['svg'] = 'image/svg+xml';
  return $mimes;
}

add_filter('upload_mimes', 'cc_mime_types');

A lightweight, intuitive WordPress theme to enable flexible developement.

  • Lighting-fast installer
  • Intuitive SASS structure
  • Bloat-free

Build with Barebones