Skip to content

Uploading SVG Images to WordPress: A Definitive Guide

Alejandro Frades
SVG WordPress Modular (1)

SVG, which stands for “Scalable Vector Graphics,” is a popular image format. In today’s digital era, optimizing your WordPress website includes understanding how to upload SVG to WordPress for specific situations where it is the best option.

Why Use SVG in WordPress?

Scalable Vector Graphics or SVG images are ideal for use on your WordPress website in elements such as logos or icons. Due to their scalable and resolution-independent nature, they maintain sharpness and clarity regardless of the size at which they are displayed. This is particularly useful considering the variety of screen sizes and resolutions we have today. Additionally, SVG files are often smaller in size, which can help speed up your website’s loading time.

How to Enable SVG Support in WordPress with Plugins

By default, WordPress does not allow the upload of SVG files due to security concerns. However, there are several ways to enable SVG file uploads.
One option is to use a plugin like “SVG Support” or “Safe SVG“. Once you have installed either of them, you can upload SVG files to your WordPress media library.

Steps to Upload an SVG File to WordPress

  1. Download and install an SVG support plugin: To begin, go to your WordPress admin panel and navigate to ‘Plugins > Add New.’ Search for “SVG Support” or “Safe SVG,” then install and activate the plugin.
  2. Upload your SVG file: Go to ‘Media > Add New’ in your WordPress admin panel. Next, select your SVG file and click ‘Open’ to upload it.
  3. Embed your SVG file in content: Now that your SVG file is in the media library, you can add it to your pages or posts just like you would with any other image. You can also use it in places like the customizer to add a menu logo or footer logo.

Uploading SVG to WordPress without Plugins

If you prefer not to use plugins to enable SVG file uploads in WordPress, you can do it manually by following these steps:
1. Add a Filter to the functions.php File

To enable SVG support in WordPress without plugins, you can add a filter to your theme’s functions.php file.

Here are the steps to do it:

a. From your WordPress admin panel, go to ‘Appearance > Theme Editor.’

b. In the list of files on the right, look for the ‘functions.php’ file and click on it to edit.

Note: This is only possible if you have theme editing enabled. If not, you’ll need to locate the file via FTP or your hosting’s file manager.

c. Copy and paste the following code at the end of the file:

function enable_svg_support($mimes) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'enable_svg_support');

d. Click on ‘Update File’ to save the changes.

This code will allow the upload of SVG files to your media library.

2. Fix SVG Display in the Media Library

When you upload SVG files to your WordPress media library, you may not be able to see thumbnail images. To fix this issue, you need to add another snippet of code to your functions.php file:

function fix_svg_preview($response, $attachment, $meta) {
    if ($response['mime'] === 'image/svg+xml') {
        $response['sizes'] = [
            'thumbnail' => [
                'url' => $response['url'],
                'width' => $response['width'],
                'height' => $response['height'],
            ],
        ];
    }
    return $response;
}
add_filter('wp_prepare_attachment_for_js', 'fix_svg_preview', 10, 3);

This will fix the thumbnail display issue in the media library.

3. Upload and Use SVG Files in Your Content

Once you have enabled SVG file support in WordPress with or without plugins, you can follow these steps to upload and use SVG files in your content:

a. Go to ‘Media > Add New’ in your WordPress admin panel.

b. Select your SVG file and click ‘Open’ to upload it.

c. Once uploaded, you can add the SVG file to your pages or posts just like you would with any other image in JPG or PNG formats.

Note that uploading SVG files without plugins may be less secure than using a dedicated plugin, as plugins often include additional security measures. Make sure to keep your SVG files clean and free from malicious code to minimize security risks.

After you have uploaded your SVG images to WordPress, we recommend reading our guide to optimizing images in WordPress to ensure that your images not only look great but also contribute to optimal website performance.

Common Issues When Uploading SVG to WordPress and How to Resolve Them

While uploading SVG files to WordPress can be a straightforward task with the help of plugins, sometimes issues may arise. One of the most common issues is that the SVG file does not display correctly after uploading. This can be caused by an error in the SVG file itself, an issue with the SVG support plugin you are using, or a problem with your server’s security settings.

If your SVG file is not displaying correctly, try opening it in a vector graphics editor such as Adobe Illustrator and save it again. If that doesn’t work, try disabling and reactivating your SVG support plugin or try a different plugin. If you still encounter issues, you may need to contact your hosting provider to discuss possibilities for adjusting the security settings.

Conclusion

Uploading SVG images to WordPress can be an excellent way to enhance the appearance and performance of your website. With the help of SVG support plugins, this process can be easy and seamless. Make sure to consider potential issues and how to resolve them to ensure that your experience with SVG in WordPress is as smooth as possible.

Alejandro Frades marketing specialist Modular
Autor
Alejandro Frades
Marketing Specialist
La mente detrás de los contenidos sociales de Modular. Siempre al tanto de las últimas tendencias para aprovecharlas y hacer que el mundo digital sea más ameno y entretenido.

Subscribe to our Newsletter about the web world