Updated for Divi 5: WordPress still blocks SVG uploads by default, but Divi 5 now lets administrators upload SVG files and cleans them on upload. I tested it with Divi 5.18 and rewrote this post, because the old code snippet is no longer needed with Divi 5 (and it never checked the files for anything harmful).
Can you upload SVG images to WordPress?
Not out of the box: WordPress (I checked version 7.1) still doesn’t include SVG in its list of allowed file types. That’s on purpose, because an SVG file is code and can contain scripts, so you need something that allows SVG uploads and ideally also sanitizes the files.
SVG images are perfect for logos and icons: they stay sharp at any size and are usually tiny. So it’s worth enabling them, just in a safe way.
How to upload SVG images in Divi 5
If you’re an administrator, simply upload the SVG to the Media Library: on my Divi 5.18 test site it worked without any plugin or code. Divi 5 adds SVG to the allowed file types for users who can manage theme options (administrators), and it sanitizes every SVG when it’s uploaded.
To check it, I uploaded a test SVG with a <script> tag and an onload attribute inside. Divi removed both before the file was saved, and the circle in the image stayed untouched.
A few things to know:
- Only administrators. Divi 5 removes SVG from the allowed file types for other roles (editors, authors), on purpose, even when a code snippet adds it. I tested this with the snippet from the original version of this post.
- The SVG module. Divi 5 has an SVG module that can show pasted SVG code or an uploaded SVG file (its Source Type setting), and the Icon Manager lets you upload your own SVG icons.
- Elegant Themes’ advice. Their help article How to Upload SVG and JSON Files still recommends a plugin for SVG uploads outside the Icon Manager. If uploading doesn’t work on your site, follow it.
How to upload SVG images without Divi 5
Use a plugin that allows SVG uploads and sanitizes the files, such as Safe SVG or SVG Support. That’s the safest way on a Divi 4 site or any other theme.
One thing to keep in mind: with Divi 5 active, SVG uploads stay limited to administrators even with one of these plugins, because Divi removes SVG from the other roles’ allowed file types (that’s how Divi 5.18’s code works; I didn’t test every plugin).
The old functions.php snippet (and a safer version)
The snippet from the first version of this post only adds SVG to the allowed file types. It doesn’t check what’s inside the file, so anyone who can upload media could upload an SVG with harmful code. Here is the original:
// Allow SVG uploads
function allow_svgimg_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'allow_svgimg_types');
If you can’t use a plugin and you only upload SVG files you made or trust, at least limit it to administrators:
// Allow SVG uploads for administrators only (no sanitizing!)
function dl_allow_svg_uploads( $mimes ) {
if ( current_user_can( 'manage_options' ) ) {
$mimes['svg'] = 'image/svg+xml';
}
return $mimes;
}
add_filter( 'upload_mimes', 'dl_allow_svg_uploads' );
Remember to use a child theme
If you’re using Divi or any other pre-made theme, don’t forget to make a child theme first and add the code to the functions.php file in your child theme (or use a code snippets plugin). If you make changes in the parent theme’s files, all your changes will be gone when you update the theme.
Tips for using SVG images safely
Only upload SVG files from sources you trust, keep them small and give them clear names. A few habits that help:
- Clean up the file first. Icons exported from design tools often contain extra code. A free tool like SVGOMG makes them smaller and cleaner.
- Name your files before you upload them. SVG files don’t always get a nice preview, so a clear name (like
icon-heart-pink.svg) helps you find the right one later. - Don’t give upload rights to people you don’t trust. Sanitizing helps a lot, but the safest SVG is one that comes from you.
Have questions about using SVG images in Divi? Ask in my Divi Lovers Facebook group.





