THE VECTOR FIELD GUIDE

How to Upload an SVG to WordPress (and Use It Safely)

WordPress blocks SVG uploads by default because an SVG is XML code. Learn the safe plugin method and the code method, and how to use the SVG once it is uploaded.

By Shahab Uddin · Updated

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.

  1. In WordPress admin, go to Plugins, then Add New.
  2. Search for Safe SVG, install it, and activate it.
  3. In the plugin settings, limit SVG uploads to administrators only, unless you have a clear reason to allow another role.
  4. Go to Media, then Add New, and upload the SVG file as a normal image.
  5. 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

MethodDifficultySanitises on uploadBest for
Safe SVG pluginEasyYesMost site owners who want a safe upload flow
Code, upload_mimes filter, admin onlyMedium, needs PHPNo, admin trust onlyDevelopers who control the site and trust every SVG
Convert to PNG insteadEasyNot needed, PNG is rasterFeatured images and builders that refuse SVG

Sources

Written by Shahab Uddin. Published ; updated . Corrections are welcome through the contact page.

A few useful answers

Before you hit download

Why can I not upload an SVG to WordPress?

WordPress blocks SVG uploads by default because an SVG is XML code and can carry scripts. Use a sanitising plugin such as Safe SVG, or add svg as image/svg+xml through the upload_mimes filter, restricted to administrators only.

Is uploading SVG files safe?

It is safe only with controls. Use a plugin that sanitises on upload, limit uploads to administrators, and only upload SVG files you trust. Never allow untrusted users to upload SVG files, and never upload an SVG from an unknown source.

Which plugin should I use for SVG uploads?

Safe SVG is the simplest safe choice for most sites. It sanitises SVG files on upload, shows previews in the media library, and lets you choose who can upload. Its plugin page confirms sanitised SVGs and SVGO optimisation, which is disabled by default.

Can I use an SVG as a featured image or logo?

A site logo works where the theme supports SVG logos. A featured image often does not accept SVG, because many themes expect a raster image. In that case, use a PNG copy for the featured image and keep the SVG as the source file.

Why does my SVG show as blank or broken after upload?

Check three things. First, confirm the file is a real SVG, not an HTML error page saved with an svg extension. Second, open it in a browser to confirm it renders. Third, set width and height in the block, because an SVG without dimensions can render at an unexpected size.

Will an SVG slow down my site?

A normal SVG is usually small and fast, because it is text based vector data rather than pixels. A very complex SVG with many paths can be larger, so keep the design simple and let Safe SVG optimisation reduce the file size where it is enabled.

Next, make it useful.