How to properly upload SVG on Wordpress

How to properly upload SVG on WordPress

Here’s how to properly upload SVG on WordPress.

Follow the guide on how to properly upload SVG on WordPress. This should be quick and easy.

Allow to upload SVG on WordPress

First, you need to add the SVG format to WordPress upload_mimes. You will need to use the add_filter of WordPress on upload_mimes. This will enable SVG or allow SVG files to be uploaded on WordPress

Then add a callback function that will add the SVG format. In this example its svg_mime_types()

Then, you need to use the print_media_templates action of WordPress to print a preview of your SVG file when uploaded.

Copy the code to functions.php

Copy the following code to your functions.php in your WordPress theme.

From here you should be able to upload SVG files.

Still can’t upload SVG?

After you copy the code and still cant upload SVG and if WordPress is throwing an error saying

your-svg.svg has failed to upload. Sorry this file is not permitted for security reasons.

You might want to check your SVG file before uploading to WordPress.

Sanitize your SVG

SVG files are being checked by wordpress if its secure or not. To make sure that you file is secure. You need sanitize your SVG before you upload on WordPress.

Use the following link to sanitize your SVG

http://svg.enshrined.co.uk/

Open your SVG file to a text editor.

Copy your SVG code and paste it to Dirty SVG box from the link above.

Click the green sanitize button.

Copy the sanitized code from the Cleaned SVG box and paste the code to the text editor where your SVG file is open.

Then, save your SVG file.

After you updated your SVG file, you can try to upload it on WordPress

That’s it!

This process works for me. Feel free to post a comment if you have any questions or clarifications.