SVG is the best format for logos, icons and illustrations: the files are tiny, and they stay sharp at any size. But try to upload one to the Media Library, and WordPress stops you with “Sorry, you are not allowed to upload this file type.”

I ran into this myself when I redesigned andersnoren.se. I wanted the thumbnails in the tutorials section as SVGs, so the theme could output them inline and swap their colors for the theme’s own color variables. That way, the thumbnails follow the site when you switch to light mode, without a second set of images. You can see it in action if you scroll down to the section with new tutorials, and click the dark mode button in the header. Before I could build it, though, I needed WordPress to accept the files.
In this tutorial, we’ll go through why WordPress blocks SVG uploads, how to allow them safely with a plugin, and why I won’t share the code snippet you’ll find in most other guides.
Why WordPress blocks SVG uploads
An SVG looks like an image, but it’s really a text file written in XML, and XML can do a lot more than draw shapes. An SVG can contain a <script> element, event attributes like onload, and links to other files. If someone uploads an SVG with a script in it, the script runs when a visitor opens the file’s URL, and it runs on your domain. If that visitor is a logged-in administrator, the script can act as them.
That’s why WordPress only accepts file types it considers safe, and SVG isn’t one of them. Adding SVG to core has been discussed in ticket #24251 since the start of Barack Obama’s second term in office, and the ticket is still open. The sticking point is that WordPress would need a way to clean the files on upload first, removing anything that isn’t a shape, and that’s exactly what a good SVG plugin does.
Allowing SVG uploads with Safe SVG
There are plenty of SVG plugins, and the one I install on most of my sites is Safe SVG by 10up. It started out as a proof of concept in that same core ticket back in 2015, has over a million active installs, and it sanitizes every SVG on upload: it strips out scripts, event attributes and anything else that isn’t needed to draw the image, before the file is saved.
- Go to “Plugins” → “Add New Plugin”, and search for “Safe SVG”.
- Click “Install Now”, and then “Activate”.
- Go to “Settings” → “Media”, and scroll down to “Safe SVG Settings”. Select the user roles that should be able to upload SVGs, and click “Save Changes”. I’d limit it to roles you trust, like Administrator and Editor.
- Upload your SVGs like any other image, either in “Media” → “Add New Media File” or straight from an Image block.

Safe SVG also adds previews of SVGs in the Media Library, so you can tell them apart. Files larger than 10 MB are blocked unless you check “Allow large SVG files” in the same settings section, but an SVG that large is usually a sign something went wrong in the export. Your server’s own upload limit applies too, so if a large SVG fails with a size error, see how to increase the maximum upload file size.
Uploading SVGs on WordPress.com
WordPress.com works the same way: SVG uploads aren’t allowed out of the box, but they are on paid plans once you install a plugin that adds SVG support. andersnoren.se runs on WordPress.com, and Safe SVG is what I use there. Install it from “Plugins” in your site’s dashboard, and follow the steps above. The accepted file types page in the WordPress.com support docs has the details.
What about doing it without a plugin?
Search for this topic, and many guides will also give you a code snippet: a few lines for functions.php that add SVG to the list of allowed file types. I’m not going to include that snippet here.
It would allow you to upload SVGs, but it wouldn’t make them safe. It just turns off the check. Nothing looks at what’s inside the files, so every SVG goes straight into your Media Library, and if you’re unlucky, malicious scripts go with them. That’s the exact risk WordPress was protecting you from in the first place.
Sanitizing SVGs properly is hard, and the stakes are high. That’s why the core ticket has been going around in circles for over a decade. As SVGs become more and more common, there’s still hope that we will eventually see support for SVG uploads land in WordPress core. Until then, do what I did for this redesign and use the Safe SVG plugin.
Notes
- In an Image block, the SVG is shown with an
<img>tag, like any other image. Scripts in the file don’t run there, but your theme’s CSS can’t reach inside it either, so you can’t change its colors. To do that, the SVG has to be output inline, which is what Preset does with the tutorial thumbnails. Only do that with sanitized files. - Export your SVGs with the text converted to outlines, so they look the same without the fonts installed. Running them through an optimizer like SVGO can make them a lot smaller: it cut the file size of my thumbnails in half, with no visible difference.
- If you deactivate the plugin later, the SVGs you’ve already uploaded stay in the Media Library and keep working on your site. You just can’t upload new ones.