SVG Support

Enable SVG file uploads in your WordPress media library with automatic security sanitization. Use crisp vector graphics for logos, icons, and illustrations that scale perfectly on any screen size.

Use Cases

  • Upload your company logo in SVG format for perfect scaling on all devices
  • Use vector icons that stay sharp on retina and high-DPI displays
  • Reduce file sizes compared to multiple PNG versions for different sizes
  • Display scalable illustrations and graphics without quality loss

How It Works

  1. Enable the module in Switchboard
  2. SVG uploads are now allowed in the media library
  3. Each SVG is automatically sanitized during upload for security
  4. Use SVGs anywhere you’d use other images (posts, featured images, etc.)

Where to Find It

Location: Upload SVGs through Media → Add New or the media button in any editor.

Why SVGs Need Special Handling

WordPress blocks SVG uploads by default because SVG files can contain malicious code (JavaScript, external references). This module:

  1. Enables SVG uploads
  2. Automatically sanitizes each file during upload
  3. Removes dangerous elements and attributes
  4. Keeps the visual content intact

Security Sanitization

Every SVG uploaded is automatically cleaned:

Removed Elements

ElementReason
<script>Can execute JavaScript
<object>Can embed external content
<embed>Can embed external content
<iframe>Can load external pages
<link>Can load external resources
<style>Can contain malicious CSS
<base>Can redirect URLs
<meta>Can contain redirects

Removed Attributes

AttributeReason
onclick, onload, etc.Event handlers can execute code
javascript: URLsCan execute scripts
data: URLsCan contain encoded scripts

Benefits of SVG

BenefitDescription
ScalabilityLooks perfect at any size, from favicon to billboard
Small file sizeOften smaller than PNG, especially for simple graphics
Retina-readyAutomatically crisp on high-DPI displays
StylingCan be styled with CSS (colors, animations)
AccessibilityCan contain text that screen readers can access

Best Practices

When to Use SVG

  • Logos and brand marks
  • Icons and UI elements
  • Simple illustrations
  • Infographics and charts
  • Decorative graphics

When to Use Other Formats

  • Photographs (use JPEG/WebP)
  • Complex detailed images (use PNG/WebP)
  • Images requiring transparency with photos (use PNG)

Optimizing SVGs

Before uploading, optimize your SVGs:

  1. Remove editor metadata — Programs like Illustrator add extra data
  2. Simplify paths — Reduce unnecessary complexity
  3. Use SVGO — Tools like svgo.com optimize file size

Using SVGs in WordPress

In the Block Editor

  1. Add an Image block
  2. Upload or select your SVG from the media library
  3. The SVG displays and scales properly

SVGs work as featured images, but some themes may not display them correctly in all contexts (like thumbnails in archive pages).

In Theme Templates

<img src="<?php echo get_template_directory_uri(); ?>/images/logo.svg" alt="Logo">

Inline SVG (Advanced)

For maximum control (CSS styling, animations), output SVG code directly:

<?php echo file_get_contents(get_template_directory() . '/images/icon.svg'); ?>

FAQ

Is it safe to allow SVG uploads?With this module, yes. Every SVG is sanitized during upload, removing potentially dangerous code. However, only allow trusted users to upload files — this is good practice regardless of file type.
Why doesn’t my SVG show in the media library thumbnail?SVG thumbnails require CSS fixes which this module provides. If you still see a generic icon, try refreshing the page or clearing your browser cache.
Can I upload SVGs with embedded fonts?Embedded fonts within SVGs generally work. For external font references, convert text to outlines in your design software before exporting.
Why is my SVG displaying very small or very large?SVGs without defined width/height attributes or viewBox may display incorrectly. Open the SVG in a text editor and ensure it has a viewBox attribute defined.
Will existing SVGs in my library be sanitized?No, sanitization only happens during upload. Existing SVGs remain unchanged. If you’re concerned about existing files, re-upload them through this module.

Export SVGs from design software with “Export for Web” or equivalent options. This removes unnecessary metadata and reduces file size.

While SVG sanitization removes known dangerous elements, only allow file uploads from trusted users. This security principle applies to all file types, not just SVGs.

PRO

Get access to all 147 modules with a single license

Upgrade to Pro