DEV Community

[Comment from a deleted post]
Collapse
 
gsarig profile image
Giorgos Sarigiannidis

By the way, for anyone wanting to use SVG icons with WordPress: by default SVG uploads are disabled, as the .svg files are vulnerable to XML based attacks. So, to upload SVGs to WordPress, first you need to enable it, and you should do it in a safe way, making sure that you sanitize it first. My preferred way is with the Safe SVG plugin (there are other alternatives as well). Then, you can upload SVGs like any other image.

Personally, to avoid cluttering my PHP with plain svg code and making it easier to add them on my templates, I made a method on an mu-plugin that I use, which can be called like that:

echo \DareDev\Element::inline_svg( $img_id_or_url, 'example-class', 'example-id' );
Enter fullscreen mode Exit fullscreen mode