Allow SVG through WordPress Media Uploader

Avatar of Chris Coyier
Chris Coyier on (Updated on )

NOTE: As of 4.7.1 this isn’t working exactly as published here anymore. Comment thread starts here. I’ll update this once the best way to handle it becomes clear. This is the best I got so far.

For your functions.php file or a functionality plugin:

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

Without this, SVG files will be rejected when attempting to upload them through the media uploader.

Before WordPress 4.0, you also make them display properly in the Media grid. But that’s broken now. If anyone knows how to fix, let me know!

function fix_svg_thumb_display() {
  echo ' img[src$=".svg"], img[src$=".svg"].attachment-post-thumbnail { 
      width: 100% !important; 
      height: auto !important; 
add_action('admin_head', 'fix_svg_thumb_display');