Enable SVG in WordPress Media Library using a function

E

In 2022, the WordPress Media Library does not permit uploading SVG file types by default.

Trying to upload an SVG file to the WordPress Media Library results in the warning, “Sorry, this file type is not permitted for security reasons.”

WordPress warning: "Sorry, this file type is not permitted for security reasons."
WordPress warning: “Sorry, this file type is not permitted for security reasons.”

Therefore, to change your site’s functionality and permit SVG upload, you’ll need to edit your theme or child theme’s function.php file.

Function for adding SVG support in WordPress

Below is a simple function enabling SVG support in the WordPress media library. Add functions to your site’s function.php file.

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

Easily add code to your functions.php file with the plugin CODE SNIPPETS

Because it is easy, I prefer to use the WordPress plugin CODE SNIPPETS to organize and add personalized code updates to my WordPress site’s functions.php file.

The same Enable SVG PHP code is shown below in a screenshot. The screenshot is SVG enabling code applied to a WordPress site via the CODE SNIPPETS plugin.

PHP code placed in CODE SNIPPETS that updates the function.php to permit the upload of SVG files

I hope this blog post has successfully helped you fix the “Sorry, this file type is not permitted for security reasons.” warning in WordPress.

Happy Blogging!

About the author

Kelly Barkhurst

Designer to Fullstack is my place to geek out and to share tech solutions from my day-to-day as a designer, programmer, and business owner (portfolio). I also write on Arts and Bricks, a parenting blog and decal shop that embraces my family’s love of Art and LEGO bricks!

Add comment

By Kelly Barkhurst

Recent Posts

Archives

Categories