XSS Security & Vector Sanitizer

Sanitized SVG Icon Cleaner for WordPress

Strip malicious JavaScript payloads, event handlers, and XML doctypes from SVG icons. Outputs clean vector markup and custom wp_kses allowed tags arrays for secure front-end rendering.

Drop .svg file here
Paste Raw SVG Markup (from Figma/Illustrator) Drag & Drop Enabled
XSS-Free Vector
Production WordPress Helper: theme_get_icon( $slug ) with wp_kses:
How to Use This Tool

How to Use the Sanitized SVG Icon Cleaner for WordPress

Follow this 4-step workflow to configure, generate, and deploy production-ready code into your WordPress theme.

1

Paste, Drop, or Upload SVG Vector Code

Choose a preset icon (Bell XSS test, Security Shield, Feather Arrow), upload an .svg/.txt file, or paste inline SVG code exported from Figma or Illustrator.

Input: .svg or Raw SVG XML Code
2

Toggle Sanitization & Color Normalization Rules

Enable or disable "Normalize to currentColor", "Strip XML Declaration & Metadata", "Strip Script & Event Attributes", and "Format & Trim Whitespace".

4 Real-Time Cleanup Controls
3

Inspect Clean SVG, Live Render & PHP Helper

Check the Sanitized SVG pane or toggle "Live Render" to preview the 64px vector output, and review the generated codetowp_get_icon() wp_kses() PHP helper below it.

Exports: icon-sanitized.svg & inc-svg-icons.php
4

Download or Embed via codetowp_get_icon()

Download icon-sanitized.svg or inc-svg-icons.php (add extra SVG tags like <g> to $allowed_tags manually if complex illustrations require them) and call codetowp_get_icon().

Target Location: wp-content/themes/{theme}/inc/

Inline SVG icons keep WordPress navigation bars and feature grids razor-sharp without extra font files, yet raw vector exports from design tools often carry bloated metadata—or dangerous script vectors if pasted from unverified sources. The CodeToWP Sanitized SVG Icon Cleaner for WordPress cleans SVG markup in the browser and builds a ready-to-use codetowp_get_icon() helper backed by WordPress’s wp_kses() whitelist.

Sanitized SVG Icon Cleaner for WordPress stripping XSS vectors and generating wp_kses arrays
Strip XML prologs and inline event handlers, normalize to currentColor, and export inc-svg-icons.php.

Who the Sanitized SVG Icon Cleaner for WordPress Is Built For

Design tools like Figma, Illustrator, and Sketch export XML declarations, doctypes, comments, and <metadata> blocks that bloat HTML payloads. Even riskier, unvetted SVG snippets can embed <script> tags, javascript: href URIs, or inline event handlers such as onload and onerror. Furthermore, outputting dynamic SVGs in WordPress templates requires an explicit wp_kses() tag whitelist because standard wp_kses_post() strips SVG elements. Using our Sanitized SVG Icon Cleaner for WordPress keeps theme icon helpers fast and XSS-safe.

Features, Settings & Supported Outputs

  • Presets & File Upload: Test with 3 built-in samples (including an XSS-tainted Heroicons Bell test icon, Lucide Shield, and Feather Arrow), drag-and-drop or upload .svg / .txt files, or paste raw markup.
  • 4 Cleanup & Normalization Toggles: Independently toggle Normalize to currentColor (replaces non-none/non-transparent fill and stroke values), Strip XML Declaration & Metadata (<?xml?>, <!DOCTYPE>, <metadata>, <!-- comments -->), Strip Script & Event Attributes (<script>, on* handlers, javascript: URIs), and blank-line trimming.
  • Two Live Outputs & Render Preview: Generates sanitized SVG markup (downloads as icon-sanitized.svg) alongside a complete inc-svg-icons.php helper defining codetowp_get_icon( $slug = 'custom-icon', $class = '' ) with an allowed-tags array covering svg, path, circle, rect, line, polyline, and polygon, plus a sandboxed Live Render preview.

Practical Example: Cleaning an XSS-Tainted SVG Icon

Sample Raw SVG Input

<?xml version="1.0" encoding="UTF-8"?>
<!-- Exported Icon -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#1e293b" stroke-width="2" onload="alert(1)">
  <script>alert('xss')</script>
  <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
</svg>

Expected Cleaned Output & PHP Helper Extract

// Sanitized SVG:
// <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" >
//   <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
// </svg>

// Generated inc-svg-icons.php usage:
echo codetowp_get_icon( 'custom-icon', 'w-5 h-5 text-primary' );

Result Explanation: The XML declaration, comment, <script> payload, and onload attribute are stripped cleanly, stroke="#1e293b" converts to currentColor so CSS classes style the icon dynamically, and codetowp_get_icon() escapes output via wp_kses().

Practical Use Cases

  • WordPress Theme Developers: Replace heavy icon font libraries with lightweight inline vectors rendered via codetowp_get_icon().
  • Frontend Developers: Convert fixed hex icon strokes from Figma into CSS-inherited currentColor icons.
  • Agencies: Standardize safe UI icon rendering inside custom headers, menus, and buttons with strict wp_kses() sanitization.
  • Freelancers: Strip bloated editor namespaces from client-supplied vector icons before embedding them in custom themes or Elementor widgets.

Limitations & Compatibility

  • Regex Sanitization Scope (Not a Full XML DOM Sanitizer): The browser cleaner removes XML declarations, doctypes, metadata, comments, <script> tags, quoted on* attributes, and javascript: URIs via regex. Do not rely on client-side regex alone to sanitize untrusted user uploads—advanced SVG payloads (<foreignObject>, <use>, <style>, data: URIs, or unquoted handlers) require server-side DOM/XML sanitization if handling untrusted user submissions.
  • Allowed-Tags Whitelist Covers Core Icon Primitives: The generated $allowed_tags PHP array permits svg, path, circle, rect, line, polyline, and polygon. Grouped icons or complex illustrations using <g>, <defs>, gradients, <text>, or fill-rule will have unlisted elements stripped by wp_kses() unless you add those tags/attributes manually to $allowed_tags.
  • Helper & Style Edge Cases: Passing $class to codetowp_get_icon() inserts class="..." after <svg (avoid having a pre-existing class= on the root <svg> or empty <svg> without attributes), and currentColor normalization converts multi-color attribute icons to monochrome while ignoring inline style="fill:..." properties.
  • Compatibility: Generated PHP works cleanly on WordPress 5.0–6.7+ and PHP 8.0–8.3+.

Next Steps & Related CodeToWP Tools

Read our tutorial on Sanitizing Inline SVG Icons in WordPress with wp_kses(), embed cleaned vectors generated by the Sanitized SVG Icon Cleaner for WordPress inside custom blocks built with our Elementor Widget Generator, reinforce theme security using the Security Snippet Generator, or review our WordPress Theme Security Hardening Checklist.

Frequently Asked Questions

Because SVG is an XML document format capable of containing <script> elements and inline event handlers, WordPress disables SVG uploads out of the box to prevent Stored XSS vulnerabilities.

It passes your icon markup through wp_kses() using an explicit whitelist array allowing only safe vector primitives (svg, path, circle, rect, line, polyline, and polygon) along with standard presentation attributes.

The generated PHP whitelist intentionally keeps only core single-icon elements (svg, path, circle, rect, line, polyline, polygon). Before embedding multi-layer illustrations, add g, defs, linearGradient, or clipPath rules to $allowed_tags inside inc-svg-icons.php.

When enabled, non-none and non-transparent fill and stroke attributes convert to currentColor so icons inherit your CSS text color seamlessly. Uncheck that toggle if you want to preserve multi-color fills.

Use this cleaner for developer-curated UI icons copied from Figma, Heroicons, or Lucide. If your site lets anonymous visitors upload SVGs dynamically, always run a strict server-side XML DOM sanitizer before saving files.