Does anyone know how to get wordpress to allow the use of SVG files being uploaded via the theme customiser panel?
Added the following to the theme functions.php file which allows SVG’s to be uploaded (no preview or featured image working though).
function custom_mtypes( $m ){
$m['svg'] = 'image/svg+xml';
$m['svgz'] = 'image/svg+xml';
return $m;
}
add_filter( 'upload_mimes', 'custom_mtypes' );
However this still doesn’t let me upload or choose an SVG from the file system or drag and drop one.
UPDATE (Wordpres 5+)
Make sure that each SVG file starts with:
If youâve tried simply uploading an SVG to WordPress through the Media Uploader, you may have had a few issues.
Either it gave you an error and wouldnât let you upload the file or it allowed you to upload the .svg file but just wouldnât display it. Either way, hereâs two simple steps for enabling SVG images in WordPress easily.
Note: Youâll need to be able to edit your themeâs (or child themeâs)
functions.php
file and the root.htaccess
file for this to work.Add SVG MIME Types to
functions.php
You should replace
wpcontent_
with your own namespace. This function simply adds the SVG and SVGZ (compressed SVG) to the allowed upload file types in WordPress and hooks into the upload_mimes() WordPress function.Add SVG Mime Types to .htaccess
So, open your root
.htaccess
file and add the following after the line,#End WordPress
.Save the file and youâre done! You can now save SVGs from Illustrator or Inkscape and use them on your WordPress site.
Source here
You can overcome the security warning by adding this to your current themes functions.php file.
Then you should be able to upload files with an .svg extension
Use the following code to svg support in WordPress. It will import and export of .svg media files.
Noticed that if you use “save for screens” the file won’t upload but “save as…” works (illustrator)