The short answer
WordPress blocks SVG uploads by default because an SVG file is XML code and can carry scripts. The safe way to allow it is a sanitising plugin such as Safe SVG, which cleans the file on upload and lets you limit who can upload. The code way is to add svg as image/svg+xml through the upload_mimes filter, restricted to administrators only. Only upload SVG files you trust.
Why WordPress blocks SVG
An SVG is not only a picture. It is an XML document, and it can contain scripts, external references, and other active markup. That is why WordPress does not list SVG among its allowed upload types by default. When you try to upload one, WordPress rejects it with a message about the file type not being permitted for security reasons.
This block is a safety feature, not a bug. A trusted SVG from your own design tool is normally safe, but an SVG from an unknown source can be dangerous. Never allow SVG uploads from untrusted users, and never upload an SVG you did not create or did not check.
Method 1: plugin, Safe SVG
Safe SVG is the simplest safe method for most site owners. It allows SVG uploads while sanitising the file on upload, so dangerous code is removed before WordPress stores the file. It also shows SVG previews in the media library, and lets you choose who can upload.
- In WordPress admin, go to Plugins, then Add New.
- Search for Safe SVG, install it, and activate it.
- In the plugin settings, limit SVG uploads to administrators only, unless you have a clear reason to allow another role.
- Go to Media, then Add New, and upload the SVG file as a normal image.
- Check the preview in the media library. If it shows correctly, the file is ready to use.
Method 2: code, upload_mimes filter
add_filter( 'upload_mimes', function( $mimes ) {
if ( current_user_can( 'administrator' ) ) {
$mimes['svg'] = 'image/svg+xml';
$mimes['svgz'] = 'image/svg+xml';
}
return $mimes;
} );The code method adds SVG to the allowed MIME types through the upload_mimes filter. WordPress developer docs confirm that upload_mimes filters the list of allowed mime types and file extensions, and that get_allowed_mime_types applies this filter. The snippet below adds svg as image/svg+xml, and only for administrators.
Put this code in a child theme functions.php file or in a code snippets plugin, not in the main theme functions.php file, so a theme update does not remove it. Back up the site before editing PHP. This snippet alone does not sanitise the file, so it is only safe when uploads are limited to administrators and every SVG comes from a trusted source. If other roles need to upload SVGs, use Safe SVG instead, because it sanitises on upload.
Using the SVG once it is uploaded
After upload, the SVG appears in the media library like other images. Add it to a page with an Image block, use it as a site logo where the theme supports SVG logos, and set alt text that describes the image. Check the page in a browser to confirm the SVG renders at the size you expect.
Some places do not accept SVG. Featured images and some page builders may refuse SVG files, or may show them without a preview. If a block will not accept the SVG, use the SVG in an Image block instead, or convert a copy to PNG for that one use. Keep the original SVG as the source file, so you can export a clean PNG at any size later.
- Image block: works in most cases, and keeps the SVG crisp at any size.
- Site logo: works only where the theme supports SVG logos. Check the theme settings first.
- Featured image: often not supported for SVG. Use a PNG copy if the theme requires it.
- Alt text: add it in the media library, the same way you would for a JPG or PNG.
- Dimensions: set width and height in the block, because an SVG without dimensions can render very large or very small.
Method comparison
| Method | Difficulty | Sanitises on upload | Best for |
|---|---|---|---|
| Safe SVG plugin | Easy | Yes | Most site owners who want a safe upload flow |
| Code, upload_mimes filter, admin only | Medium, needs PHP | No, admin trust only | Developers who control the site and trust every SVG |
| Convert to PNG instead | Easy | Not needed, PNG is raster | Featured images and builders that refuse SVG |
Sources
- WordPress Developer: get_allowed_mime_types, applies the upload_mimes filter
- WordPress Developer: Filter Reference, upload_mimes
- WordPress.org: Safe SVG plugin, sanitised SVGs
- Total WP Theme: How to Enable SVG Uploads in WordPress, admin restricted code example
Written by Shahab Uddin. Published ; updated . Corrections are welcome through the contact page.