Discover in this tutorial how to get WordPress to support images in SVG format using a simple code snippet.
Vector format (SVG) has the advantage that it looks 100% sharp regardless of its size, since it scales without loss of quality (hence its name ‘Scalable Vector Graphics’).
This makes it the perfect candidate for logos and other design components on a website.
But have you ever tried to upload an SVG file into WordPress?
You’ve probably come across a message similar to this one:
There was an error uploading “logo_yourwebsite.svg”
I’m sorry, this type of file is not allowed for security reasons.
SVG files are insecure by nature (they are a kind of xml). They can contain malicious code inside. That’s why it’s actually great that WordPress has this security measure.
But it can also be a drawback if you have created the SVG yourself and it is totally trustworthy.
Today you’re going to learn how to allow SVG files to be uploaded into WordPress with a simple snippet of code:
Snippet for WordPress to accept SVG files
Add the following fragment at the end of functions.php:
It’s as simple as that. Now you’ll have no problem uploading your logo (or other image) in SVG format to WordPress library.
However, since you will not be able to modify it from WordPress, I recommend you to export the image with the final size you want to use on the web.
If you are one of those who take security quite seriously (like me), when you have finished uploading the file, remove the code.
This way you avoid other users to upload SVGs from unknown sources.
As you can see, with a few lines of code you can upload your logo or other image in SVG to the WordPress library.
This is a trick as simple as it is practical for WordPress designers and developers, especially when it comes to logos.
Personally, it comes in handy. I hope you find it useful too.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉