How to Use SVG in the WordPress Block Editor
WordPress blocks SVG media uploads by default for security — here's how to work with SVG safely in Gutenberg anyway.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
Why WordPress Blocks SVG Uploads by Default
WordPress's media library rejects SVG file uploads out of the box because SVG's XML structure can embed executable scripts, a real XSS risk if any site user could upload arbitrary SVG files — this is a deliberate security default, not an oversight or missing feature.
- SVG's XML structure can embed executable scripts, an XSS risk
- Blocking SVG uploads by default is a deliberate security measure
- This affects any user-facing upload, not just admin-only contexts
Safely Enabling SVG in the Block Editor
A sanitizing plugin (like Safe SVG) allows SVG uploads while stripping dangerous elements (scripts, event handlers, external references) before storage — alternatively, for custom blocks a developer controls, hardcoding trusted SVG markup directly into the block's render function avoids the upload pipeline's restrictions entirely.
- Sanitizing plugins allow safe SVG upload for trusted admin users
- Custom block render functions can embed trusted SVG markup directly
- Avoid enabling raw, unsanitized SVG upload for untrusted user roles
Frequently Asked Questions
Is it safe to just disable WordPress's SVG upload block entirely?
Not without sanitization — removing the restriction without a sanitizing plugin re-opens the XSS risk the default block exists to prevent, especially dangerous if any non-admin user has upload permissions.
Can custom Gutenberg blocks use SVG without touching the media library?
Yes — a developer-authored custom block can embed trusted SVG markup directly in its render.php or JavaScript render function, bypassing the media upload restriction entirely since the SVG never goes through that pipeline.
Related guides
Ready to Convert Your Image to SVG?
Free online converter — no sign-up, no watermarks, results in under 3 seconds.
Try It Free — Convert Image to SVG