To add support for SVG files in the WordPress media uploader, you can use the following code in your theme’s functions.php file:
// How to add support for SVG in WordPress media library
// More snippets at wpunplugged.com
function add_svg_to_upload_mimes( $upload_mimes ) {
$upload_mimes['svg'] = 'image/svg+xml';
$upload_mimes['svgz'] = 'image/svg+xml';
return $upload_mimes;
}
add_filter( 'upload_mimes', 'add_svg_to_upload_mimes', 10, 1 );
This code will allow you to upload SVG files to your WordPress media library. Note that this will only work if your hosting environment allows uploading of SVG files. Some hosting providers block the upload of SVG files for security reasons.
You can also use a plugin like Safe SVG to allow uploading and sanitizing of SVG files. This can be a good option if you are unable to modify your theme’s functions.php file or if you want to have more control over the allowed SVG files.