Troubleshooting Common Safe SVG Issues: From Shrinking Images to Broken Animations
Content
If you're using the Safe SVG plugin on your WordPress site, you've made a great choice for security and flexibility. However, like any powerful tool, it can sometimes interact unexpectedly with your theme, other plugins, or specific SVG code. Based on common community reports, here’s a guide to diagnosing and resolving the most frequent issues.
1. SVG Image Shrinks or Disappears When Linked
The Problem: An SVG displays correctly until you add a link to it, often in a page builder like Elementor, causing it to shrink or vanish.
Why It Happens: This is typically a CSS conflict. The anchor tag (<a>) wrapping the image might have default styles (like display: block;, width: 0;, or height: 0;) that override the image's dimensions.
The Solution: Add custom CSS to target the linked image. The exact selector will depend on your theme, but a good starting point is:
a .your-svg-class, a.custom-logo-link {
width: inherit !important;
height: inherit !important;
display: inline-block !important;
}
2. SVG Animation is Broken or Removed
The Problem: An animated SVG uploads but the animation no longer works. Tags like <animate> might be stripped from the file.
Why It Happens: This is not a bug but a core security feature. Safe SVG uses a sanitizer library that strips out potentially dangerous tags and attributes by default. SMIL animation tags like <animate> are on this blocklist because they can be exploited for malicious purposes.
The Solution: You can explicitly allow these tags using a filter in your theme's functions.php file. For basic SMIL animation, add:
function allow_safe_svg_animation( $tags ) {
$tags[] = 'animate';
$tags[] = 'animateTransform';
// Add other animation tags as needed
return $tags;
}
add_filter( 'svg_allowed_tags', 'allow_safe_svg_animation', 10, 1 );
// Sometimes attributes need to be allowed too
function allow_safe_svg_animation_attrs( $attributes ) {
$attributes[] = 'vector-effect';
// Add other required attributes
return $attributes;
}
add_filter( 'svg_allowed_attributes', 'allow_safe_svg_animation_attrs', 10, 1 );
Warning: Only add tags and attributes you absolutely trust and need. Research the security implications of any tag before allowing it.
3. Double Slashes or Incorrect Paths in srcset
The Problem: The generated HTML for your SVG images shows incorrect srcset paths with double slashes (e.g., ...uploads//2021/04/image.svg), which can cause performance or display issues.
Why It Happens: This is a known bug in older versions of the Safe SVG plugin related to how it processes file paths for the responsive srcset attribute.
The Solution: Ensure you are running the latest version of the Safe SVG plugin. The development team has addressed this issue in a GitHub pull request, and the fix has been included in subsequent releases. Updating the plugin is the simplest fix.
4. SVG Not Displaying on Mobile or Front-End
The Problem: An SVG appears in the WordPress admin (e.g., in the media library or a page builder) but does not render on the public-facing front-end of the site.
Why It Happens: The causes can vary widely. It could be due to:
- Lazy Loading: A conflict with lazy loading scripts that cannot properly handle the SVG source.
- Caching: Aggressive caching plugins serving an old, broken version of the page.
- Theme/Plugin Conflict: Another plugin or your theme's CSS is hiding the image or breaking its layout.
The Solution: Follow a standard conflict-testing procedure:
- Clear All Caches: Clear your browser cache, any server-side cache, and your caching plugin's cache.
- Disable Lazy Loading: Temporarily disable lazy loading features in your theme or plugins to see if it resolves the issue.
- Conflict Test: Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and disable all other plugins except Safe SVG. If the SVG appears, reactivate your plugins one by one to find the culprit.
- Check the Code: Use your browser's inspector tool to see if the SVG
<img>tag has a brokensrcattribute or is being hidden by CSS (display: none;).
5. General Performance and Sizing Issues
The Problem: Pages with many SVGs load slowly, or SVGs occasionally flash at their original large size before snapping to their correct CSS dimensions.
Why It Happens: Safe SVG adds a function to calculate image dimensions, which can become a performance bottleneck if a page has a very high number of SVGs. The flashing is often a brief loading state where the intrinsic size of the SVG is displayed before your theme's CSS is fully applied.
The Solution: For performance, this is an issue the Safe SVG team has noted and is working to optimize in future updates. For styling issues, add robust CSS to all SVGs to ensure they are always contained:
img[src$='.svg'] {
max-width: 100%;
height: auto;
}
By understanding these common pitfalls, you can confidently use Safe SVG to enhance your website. Most issues can be resolved with a CSS tweak, a filter, or a plugin update. Always remember to test changes on a staging site first.
Related Support Threads Support
-
Incorrect symbols after uploadinghttps://wordpress.org/support/topic/incorrect-symbols-after-uploading/
-
SVG srcset path showing with two forward slasheshttps://wordpress.org/support/topic/svg-srcset-path-showing-with-two-forward-slashes/
-
No more upgrades? I got this issue with sizehttps://wordpress.org/support/topic/no-more-upgrades-i-got-this-issue-with-size/
-
No SVGs selectable on ACF Option Pageshttps://wordpress.org/support/topic/no-svgs-selectable-on-acf-option-pages/
-
Dashicons being converted to SVGhttps://wordpress.org/support/topic/dashicons-being-converted-to-svg/
-
slow performance of svg_dimensions functionhttps://wordpress.org/support/topic/slow-performance-of-svg_dimensions-function/
-
Plugin icon font problemhttps://wordpress.org/support/topic/plugin-icon-font-problem/
-
Double slash in URLhttps://wordpress.org/support/topic/double-slash-in-url-8/
-
Breaking animation in animated SVG’shttps://wordpress.org/support/topic/breaking-animation-in-animated-svgs/
-
SVG srcset path showing double slashhttps://wordpress.org/support/topic/svg-srcset-path-showing-double-slash/
-
extra slash when linking to css filehttps://wordpress.org/support/topic/extra-slash-when-linking-to-css-file/
-
SVG Browser Compatibilityhttps://wordpress.org/support/topic/svg-browser-compatibility/
-
SVG Mixed Content Issue when migrating to new websitehttps://wordpress.org/support/topic/svg-mixed-content-issue-when-migrating-to-new-website/
-
Fill-rule warninghttps://wordpress.org/support/topic/fill-rule-warning/
-
Strips baseProfile property from SVG taghttps://wordpress.org/support/topic/strips-baseprofile-property-from-svg-tag/
-
Text color setting as fill for inline SVGhttps://wordpress.org/support/topic/text-color-setting-as-fill-for-inline-svg/
-
Inline SVGhttps://wordpress.org/support/topic/inline-svg/
-
Extra slash in pathhttps://wordpress.org/support/topic/extra-slash-in-path/
-
SVG via WP Bakery “Single Image” Not Displayinghttps://wordpress.org/support/topic/svg-via-wp-bakery-single-image-not-displaying/
-
Resize SVG and Render in Chromehttps://wordpress.org/support/topic/resize-svg-and-render-in-chrome/
-
SVG Not Displaying On Websitehttps://wordpress.org/support/topic/svg-not-displaying-on-website/
-
SVG file shrinks when adding a link to it in WordPress/Elementorhttps://wordpress.org/support/topic/svg-file-shrinks-when-adding-a-link-to-it-in-wordpress-elementor/
-
Responsive inline svghttps://wordpress.org/support/topic/responsive-inline-svg/
-
SVG image not showing in backend nor frontendhttps://wordpress.org/support/topic/svg-image-not-showing-in-backend-nor-frontend/
-
Invalid download link messagehttps://wordpress.org/support/topic/invalid-download-link-message/
-
SVG Logon not showing on Mobile deviceshttps://wordpress.org/support/topic/svg-logon-not-showing-on-mobile-devices/
-
SVG logo not displayed in sitehttps://wordpress.org/support/topic/svg-logo-not-displayed-in-site/
-
Use SVG on the7https://wordpress.org/support/topic/use-svg-on-the7/
-
Cannot Move SVG Block inside columns blockhttps://wordpress.org/support/topic/cannot-move-svg-block-inside-columns-block/
-
Animated SVG on hoverhttps://wordpress.org/support/topic/animated-svg-on-hover/
-
SVG icons becomes original size some timeshttps://wordpress.org/support/topic/svg-icons-becomes-original-size-some-times/
-
Fonts in an SVG not read by other users?https://wordpress.org/support/topic/fonts-in-an-svg-not-read-by-other-users/
-
Site Logo is not visible in editor when linked to homehttps://wordpress.org/support/topic/site-logo-is-not-visible-in-editor-when-linked-to-home/
-
Rounded Cornershttps://wordpress.org/support/topic/rounded-corners-18/
-
issue with svghttps://wordpress.org/support/topic/issue-with-svg-2/
-
SVGs from photoshop not appearinghttps://wordpress.org/support/topic/svgs-from-photoshop-not-appearing/
-
Strange issue backend ok fron-end kohttps://wordpress.org/support/topic/strange-issue-backend-ok-fron-end-ko/
-
SVG Illegal string offset warning IS BACKhttps://wordpress.org/support/topic/svg-illegal-string-offset-warning-is-back/
-
Attributes Filter doesn’t workhttps://wordpress.org/support/topic/attributes-filter-doesnt-work-3/
-
filter working code example + disallowed risk referencehttps://wordpress.org/support/topic/filter-working-code-example-disallowed-risk-reference/
-
Safe SVG causing issues with photoswipe image viewerhttps://wordpress.org/support/topic/safe-svg-causing-issues-with-photoswipe-image-viewer/
-
Ho to use the svg_allowed_attribute in detail?https://wordpress.org/support/topic/ho-to-use-the-svg_allowed_attribute-in-detail/
-
2 different behaviours with SVG fileshttps://wordpress.org/support/topic/2-different-behaviours-with-svg-files/
-
svg upload issuehttps://wordpress.org/support/topic/svg-upload-issue/
-
Featured Image in Block Editor not working properly with SVGhttps://wordpress.org/support/topic/featured-image-in-block-editor-not-working-properly-with-svg/
-
Links to redirected css warningshttps://wordpress.org/support/topic/links-to-redirected-css-warnings/
-
Scale animation css stops after importhttps://wordpress.org/support/topic/scale-animation-css-stops-after-import/
-
convert in illustratorhttps://wordpress.org/support/topic/convert-in-illustrator/
-
Blocked animation?https://wordpress.org/support/topic/blocked-animation/
-
SVG damaged after uploadhttps://wordpress.org/support/topic/svg-damaged-after-upload/
-
How to change color of SVG using CSShttps://wordpress.org/support/topic/how-to-change-color-of-svg-using-css/
-
From http:// to https://https://wordpress.org/support/topic/from-http-to-https-6/