SVG Support

Description

Important Note:WordPress now requires us to have the<xml>tag in our SVG files before uploading. If you have security errors when trying to upload, please open your SVG file in a code editor such as sublime text and add the following to the very first line of your SVG file and save:

<?xml version="1.0" encoding="utf-8"?>

Your SVG should upload as normal again. I’m looking at implementing something to avoid this as soon as possible.

Thanks for your support and patience!

When using SVG images on your WordPress site, it can be hard to style elements within the SVG using CSS. Now you can, easily!

Scalable Vector Graphics (SVG) are becoming common place in modern web design, allowing you to embed images with small file sizes that are scalable to any visual size without loss of quality.

This plugin not only provides SVG Support like the name says, it also allows you to easily embed your full SVG file’s code using a simple IMG tag.
By adding the class "style-svg" to your IMG elements, this plugin dynamically replaces any IMG elements containing the "style-svg" class with your complete SVG code, rendering it inline.

The main purpose of this is to allow styling and animation of your SVG elements. Usually your styling options are restricted when using embed, object or img tags alone.

Fonctionnalités

SVG Support for your media library

Inline your SVG code

Works with the new Image Widget (WordPress 4.8+)

Style SVG elements directly using CSS

Animate SVG elements using CSS and JS

Super easy settings page with instructions

Restrict SVG upload ability to Administrators only

Set custom css target class

Extremely Simple To Use – Simplifies complex usage of SVG files

Usage

Firstly, install and activate SVG Support (this plugin).

Once activated, you can simply upload SVG images to your media library like any other file.

As an administrator, you can go to the admin settings page ‘Settings’ > ‘SVG Support’ and restrict SVG file uploads to administrators only and even define a custom CSS class to target if you wish.

If you only need to upload SVG files to use as images, you don’t need to enable « Advanced Mode”. Leaving it disabled ensures the frontend script is not enqueued and the unnecessary settings stay hidden.

With advanced mode enabled, you can embed your SVG images just like you would a standard image with the addition of adding (in text view) the class "style-svg" (or the custom class you defined) to your IMG tags that you want this plugin to swap out with your actual SVG code.

The whole IMG tag element will now be dynamically replaced by the actual code of your SVG, making the inner content targetable.
This allows you to target elements within your SVG using CSS and JS.

You can remove all other attributes from the IMG tag as it will disappear anyway.

There’s a setting to automatically add your class to the IMG tag for you when you’re inserting SVG’s in to a post or page, which also removes unnecessary tags.
Since 2.3.11, you can force all SVG files to be rendered inline with a single checkbox. Additionally, you can now choose whether to use the minified or expanded version of the JS file.

Featured Images: If a post/page is saved with your SVG as a featured image, a checkbox will display in the featured image meta box to allow you to render it inline (only if advanced mode is active).

Please Note: If your SVG isn’t showing, it’s likely that it is being displayed with 0 height and width. In this case, you will need to set your own height and width in your CSS for SVG files to display correctly.

If you’re having any issues, please use the support tab and I will try my best to get back to you quickly

Sécurité

As with allowing uploads of any files, there is potential risks involved. Only allow users to upload SVG files if you trust them. You have the option to restrict SVG usage to Administrators only from the settings page. By default, anyone with Media Library access or upload_files capability will be able to upload SVG files (that is Administrators, Authors and Editors). Please note that SVG files are actually XML which would allow someone to inject malicious code if you’re not careful with who has upload privileges.

FAQ

SVG not rendering inline since 2.3 update

SVG Support 2.3 includes a new settings section called « Advanced Mode ». Users that were inlining SVG files need to make sure this setting is checked. Go to your dashboard > Settings > SVG Support and check « Advanced Mode ». All of your original settings should still be there.

How do I disable the Javascript on the front end if I am not using inline SVG?

If you go to Settings > SVG Support in your admin dashboard, you can choose to enable « Advanced Mode » or not. If you leave it disabled, the advanced functionality and extraneous script is removed.

I’m trying to use SVG in the customizer but it’s not working.

To allow SVG to work in the customizer, you will need to modify/add some code in your child theme’s function file. Here is a great tutorial on how to do that. The important part is:

'flex-width' => true
'flex-height' => true

How do I add animation to my SVG?

You will need to edit your SVG file in a code editor so you can add CSS classes to each element you need to target within the SVG. Make sure that your IMG tag is being swapped out for your inline SVG and then you can use CSS or JS to apply animations to elements within your SVG file.

If you are using SVG Support with Visual Composer or any other page builders, you will need to make sure that you can add your own class to the image. The easiest way to do this is by using a simple text or code block in the builder to put your image code in to. Additionally, there is now a setting to force all SVG files to be rendered inline.

I'd like to say something positive, but this plugin doesn't work with some SVG file.
I uploaded several SVG images and some of them has been rejected as "potential dangerous file".
Tried more times with the same result.

Why we cant upload SVG at this stage is beyond me, but hey I read the ticket. This plugin works randomly now, some SVGs are fine. Safe SVG the other one seems to do the job. Shame as this had no freemium up sells.

Le développement vous intéresse ?

Journal

2.3.15

Had to roll back a recent PHP warnings fix due to it breaking some theme compatibility.

2.3.14

Fixed: Fatal error in some cases when removing old option from the database.

2.3.13

Fixed: PHP warnings and notices from the image widget when using SVG files and wp_debug was on.

Modified: Better front end CSS for displaying SVG attachments, both as images and inline.

Removed: DB entry for deprecated admin notice.

2.3.12

New: Native « Help » tab on the SVG Support settings page.

New: Wrapped the inline JS in a function so you can call it at will using bodhisvgsInlineSupport();.

Modified: Admin CSS to target SVG src only.

Modified: SVG Support settings page – cleaned it up a little.

Removed: Version update admin notice.

2.3.11

New: Feature to use expanded JS file rather than the minified/compressed version (useful for bundling and minifying using external caching plugins).

New: Force Inline SVG option. This feature allows you to force all of your SVG files to be rendered inline regardless of classes applied. Addresses issues where you can’t add your own class to an image for some reason. For example, some page builder image elements. Also addresses changing your target class in the settings and needing to change all of your already embedded media, allowing you to simply force render rather than update all of the classes.

Modified the readme file and descriptions a bit.

Refined some code in functions/featured-image.php line 69 to address a warning.

Updated « Requires at least » tag to 4.8 (though it should still work in older versions, there was issues with core during the 4.7 phase and it’s time for you to update anyway).

2.3.4

2.3.3

2.3.2

Modified the attribute control code that auto inserts our class to only apply to SVG files.

2.3.1

Fix: Fatal error in some cases due to admin notice.

2.3

New Feature – Advanced Mode: allows you to turn off the advanced features and simply upload SVG files like normal images. This addition also enables users to turn off the script added on front end by leaving Advanced Mode unchecked.

New Feature – Featured Image Support: If your featured image is SVG, once the post is saved you will see a checkbox to render the SVG inline (advanced mode only).

Performance – Stop inlining JS from running if image source is not SVG.

Added new stylesheet for settings page.

Moved SCSS files to their own folder.

Changed donate link so I can track it and properly thank you for your generous donations.

Added a rating link to the settings and media pages.

Cleaned up code formatting, added more comments.

Added a plugin version check.

Added notice so people are aware they may need to turn on the advanced mode.

2.2.5

FIX: Display SVG thumbnails in attachment modals.

2.2.4

FIX: Added function to temporarily fix an issue with uploading in WP 4.7.1

2.2.32

Changed text domain to match plugin slug for localization.

2.2.31

Attempt to fix ability to translate

2.2.3

Modified code in svg-support/js/svg-inline.js and svg-support/js/min/svg-inline-min.js to allow JS control of the SVG elements and detect if they have been loaded (IMG tag swapped out). Thanks to laurosello for this suggestion and code contribution.

Fixed SVG thumbnails not displaying correctly in list view of the media library.