How to upload SVG files in media. - WPTRINITY

How to upload SVG files in media.

WordPress supports multiple image formats, including .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.

There are two ways to upload SVG in WordPress.
1. With the help of the SVG support plugin.
2. With manually add code in your site’s functions.php file.

1: Use the SVG Support plugin

If you’re looking for the fastest way to add SVG to WordPress, this is it. We’re going to use the SVG Support plugin, which enables this particular image format and adds support for it to your media library:
https://wordpress.org/plugins/svg-support/

You just need to install and activate the plugin.

WordPress now requires us to have the <xml> tag in our SVG files before uploading. Please open your SVG file in any code editor (such as sublime text) and add the following to the very first line of your SVG file and save, so that you don’t encounter security errors:

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

However, there are two more settings you might want to change depending on your needs. First off, let’s go to the Settings → SVG Support tab:

2: With your site’s functions.php file

Every WordPress website has its own functions.php file. You are adding SVG support to WordPress through a few lines of code in your site functions.php.

 function addsvg_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', 'addsvg_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, which should work without a hitch!

Leave a Comment

Your email address will not be published. Required fields are marked *