Adding a custom SVG to a plugin

I am looking to add a custom SVG icon to a plugin I am working on, but couldn’t find any documentation or topics on how to do so. All the documentation seems to be on doing it for a theme.

The register_svg_icon function seems to be only for FA icons, based on other plugin repos I’ve seen.

I imagine I can probably just put the SVG inside the public folder and pull it like a normal image, but I’d like to avoid it as a last resort.

1 Like

register_svg_icon will work for any SVG, it isn’t specific to Font Awesome

So you’d add a new sprite with your icon, like svg-icons/sprite.svg — the guidance on the spritesheet is the same as Replace Discourse's default SVG icons with custom icons in a theme (so make sure to set an id)

Then in plugin.rb you can do:

register_svg_icon "my-svg-id"

5 Likes

It works! Thank you!

I don’t suppose there’s a way to have the server watch for changes to the SVG file? Its a very minor inconvenience to refresh the page (and sometimes the dev server itself) every time I change the SVG.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.