How to Add Vector Images in WordPress

How to Add Vector Images in WordPress

How to Add Vector Images in WordPress-: SVG is an image format like other images. In fact, it’s actually a markup language that’s used to create two-dimensional images composed of vectors. It is like another image format that we use in our daily life.

Advantages of Vector images over other images are as follows-:

  • They take up less space. Instead of pixels, SVGs are composed of vectors. So your images will weigh less, which should help your site load faster.

The key difference between a pixel and vector-based graphics is how the image is structured. Pixel-based graphics are made up from lots of tiny physical squares (or ‘pixels‘) whereas vector graphics are mapped out using mathematical equations which calculate where the edges of the shapes sit in relation to one another.

  • You can scale SVG Images easily, as vectors can be scaled upwards or downwards without any loss in quality (or change in file size).
  • You can animate SVGs with CSS. Vectors can be animated using CSS, which can make for some unique effects.

WordPress Supports many image formats like .jpg.jpeg.png, and .gif. However, it doesn’t enable you to use Scalable Vector Graphics (SVGs), which is one of the most flexible image types out there. In this post, I will explain how you can use SVG images on your WordPress website.

How to Add Vector images to your WordPress Website-:

1.Using SVG support Plugin-:

How to Add Vector Images in WordPress

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.

SVG support 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 embedobject or img tags alone.

Silent Features of SVG Support Plugin-:

  • 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

Firstly, install and activate SVG Support 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. For advanced use: Enable the “Advanced Mode” under Settings > SVG Support.

How to Add Vector Images in WordPress

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.

For example:

<img class="style-svg" alt="alt-text" src="image-source.svg" />


<img class="your-custom-class" 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 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 into 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.

Security Risk with SVG Image file-:

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. 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).

How to Add SVG image support to Your WordPress Website using function.php file

Every WordPress website has its own functions.php file. This essential component includes important functions, classes, and filters. It’s also your ticket to adding SVG support to WordPress through a few lines of code. You can use Functionality Plugin to add any code to your WordPress Website function.php File.

How to Add Vector Images in WordPress

Functionality Plugin will add the code to your Function.php file without tempering your original file.

How to Add Vector Images in WordPress

If you do not want to use the plugin, you can use you hosting cPanel using FileZilla FTP client. Read my complete guide How to Use FileZilla FTP Client with your WordPress Hosting. Once you connect to your hosting Cpanel download function.php file as backup.

Access the functions.php file now by right-clicking on it and choosing the View/Edit option. This will open it using your default text editor. Now, scroll to the bottom and paste this code snippet there:

function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg+xml';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
add_filter('upload_mimes', 'add_file_types_to_uploads');

Save your changes to the file and close it. Then you can return to your dashboard and test your new feature by uploading an SVG file to your media library.

Thanks for reading…“Pardon my grammar, English is not my native tongue.”

If you like my work, Please Share on Social Media! You can Follow WP knol on Facebook, Twitter, Pinterest and YouTube for latest updates. You may Subscribe to WP Knol Newsletter to get latest updates via Email. You May also Continue Reading my Recent Posts Which Might Interest You.

About Amar Patel 263 Articles
Hi, I am Amar Patel from India. Founder, Author and Administrator of I am a Simple Average Man who Loves life and Love living life.Professionally I am a Mechanical Engineer. Apart from my Job, I Love to write the things around WordPress WordPress CMS.