How to add support for SVG in WordPress media library

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.

Share this post

You might also like...

Sucuri for WordPress Review
Plugins

Sucuri for WordPress Review

Sucuri for WordPress is a powerful security plugin that helps protect your website from hackers and malicious software. It provides a comprehensive website security solution,

Read More »

Comment

Your email address will not be published. Required fields are marked *