Out of the box, WordPress allows quite a few file types to be uploaded to the media library, but SVGs (Scalable Vector Graphics) aren’t one of them.
To allow SVG upload, simply add this code to your theme’s functions.php
file:
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
Now you can use SVGs everywhere!
They work like any other image type, except that WordPress won’t give you proper dimensions when using an image object. You can get around this by omitting the width and height attributes on the image, and using this CSS to force the image to fill its container, to a maximum of its original size:
.svg-image {
max-width:100%;
height:auto;
width:auto;
}
Enjoy!