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.
The main purpose of this is to allow styling of SVG elements. Usually your styling options are restricted when using
img tags alone.
- SVG Support for your media library
- Style SVG elements directly using CSS
- Super easy settings page with instructions
- Restrict SVG upload ability to Administrators only
- Set custom css target class
- Extremely Simple To Use
Firstly, install SVG Support (this plugin) and activate it.
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 simple functionality to upload SVG files, then you don’t need to enable “Advanced Mode” which will make sure that the frontend script is not enqueued for performance and will hide the unnecessary settings.
For advanced users, enable the “Advanced Mode” under Settings > SVG Support. Then 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. You can also remove any other attributes from the tag and use CSS to manage the size. There is also a setting to automatically add your class to the IMG tag for you when you’re inserting it in to a post or page.
<img class="style-svg" alt="alt-text" src="image-source.svg" />
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.
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: You will need to set your own height and width in your CSS for SVG files to display correctly.
If you are having any issues, please use the support tab and I will try my best to get back to you quickly
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.
- I am open to your suggestions and feedback – Thanks for using SVG Support!
- Drop me a line @benbodhi or @GoWebben on Twitter
- Follow me on my Facebook page
- Or circle +GoWebben on Google Plus ?
Note: This is the second plugin I have submitted to the WordPress repository, I hope you like it. Please take a moment to rate it and click ‘works’ under compatibility with your version of WordPress.
As always, feel free to send me any suggestions.
Idea Behind / Philosophy: I needed an easy way to include SVG support in sites instead of having to copy and paste the code for each one. I also needed the ability to make odd shaped image links which SVG allows by embedding the links in the SVG file directly. I found a really cool snippet of jQuery written by Drew Baker a while ago and have used it (modified for WordPress) a few times until I was inspired to build it all into a plugin for ease of use and to share with others. Now styling SVG elements is super easy ?
- Option to choose which user ID can access the settings
- Option to choose specific user ID’s for usage restriction (both helpful if you have multiple administrators)
Again, feel free to shoot me suggestions
Thanks to laurosello for his code contribution in svg-inline.php.
Thanks to Ogi Djuraskovic from first site guide for providing the Serbian translation!
Thanks to Apasionados del Marketing for the Spanish translation.
Logo By W3C, CC BY 2.5, https://commons.wikimedia.org/w/index.php?curid=1895005.