WP Coder has two ways to let editors put an SVG icon into a snippet from the Gutenberg block. They are separate attribute types, so it is always clear where an icon comes from:
| SVG File | Icon | |
|---|---|---|
| Attribute type | SVG File (media library) | Icon (Icons page) |
| Where icons live | Media Library — any SVG file | WP Coder Pro → Icons — a named library |
| The block stores | the file’s attachment id | the icon’s name, e.g. check |
| On the page | a sprite embedded at the end of that page | a reference into icons.svg, one file for the whole site |
| Browser cache | per page | the file is loaded once and reused on every page |
| Best for | one-off artwork, logos, files editors upload themselves | a consistent icon set used across the site |
Both print a real inline <svg> (not an <img>), so an icon can take its colour from CSS, and both work in a Repeater.
SVG File (media library)#
Set it up#
- In the snippet, open Attributes → Add attribute, pick the type SVG File (media library) and give it a name, e.g.
logo. - Optional: click
{ }next to the field for the options Follow text color (color) and Always full markup (no sprite) (inline). - Put it in the HTML:
<span class="logo">{{$logo}}</span>.
In the block, the field shows the SVG files of the media library with a search box; Media Library uploads a new one (SVG uploads must be allowed: Snippets → Media & Embeds → Allow SVG Uploads).
How it works#
Every SVG file used on a page is added once to a hidden sprite printed at the end of that page, and each use is a short reference to it:
<svg class="wpc-svg" width="24" height="24" viewBox="0 0 24 24"><use href="#wpc-svg-123"></use></svg>
…
<svg style="position:absolute;width:0;height:0"> <!-- end of the page -->
<symbol id="wpc-svg-123" viewBox="0 0 24 24">…</symbol>
</svg>
The file is read from the media library and cleaned again every time — scripts, event handlers and anything that is not SVG are removed — so only safe markup reaches the page.
Placeholders#
For an attribute named logo:
| Placeholder | Output |
|---|---|
{{$logo}} |
The icon |
{{$logo_inline}} |
The full SVG markup, never the sprite |
{{$logo_img}} |
An <img loading="lazy"> tag |
{{$logo_url}} |
The file’s URL |
{{$logo_id}} |
The attachment id |
{{$logo_alt}}, {{$logo_width}}, {{$logo_height}} |
Alt text and size |
Repeater sub-field: logo:svg or logo:svg:color → {{loop.logo}}, {{loop.logo_url}}, …
Icon (Icons page)#
1. Add icons on WP Coder Pro → Icons#
Paste SVG code, or upload several .svg files or a .zip at once. Each icon gets a name (arrow-right), a label and an optional set. Icons are cleaned when saved (no scripts, no editor metadata, coordinates trimmed to 3 decimals).
2. The sprite file icons.svg#
Every change on the Icons page rewrites one file, wp-content/uploads/wp-coder/icons.svg, with one <symbol> per icon. The Sprite file box on the Icons page shows its size and a link to it.
3. Add an Icon attribute#
- In the snippet, Attributes → Add attribute, type Icon (Icons page), name e.g.
icon. - Optional
{ }options:color,inline(as above). - HTML:
<span class="card__icon">{{$icon}}</span>.
In the block, the field lists the icons of the Icons page with a search box; pick one and the preview updates. In a Repeater use icon:library_icon (or icon:library_icon:color).
4. What the page gets#
{{$icon}} becomes a reference into the file:
<svg class="wpc-svg wpc-icon" width="24" height="24" viewBox="0 0 24 24" role="img" aria-label="Check">
<use href="/wp-content/uploads/wp-coder/icons.svg?v=3813158805#wpc-i-check"></use>
</svg>
- The browser downloads
icons.svgonce, on the first page that shows an icon, and takes it from cache on every other page. Pages without icons never load it. ?v=…changes whenever the library changes, so visitors never see an outdated icon.- The page HTML carries only these short references — no icon markup.
Placeholders#
For an attribute named icon:
| Placeholder | Output |
|---|---|
{{$icon}} |
The icon (a reference into icons.svg) |
{{$icon_url}} |
The link to the icon: …/icons.svg?v=…#wpc-i-check |
{{$icon_inline}} |
The full SVG markup, never the sprite |
{{$icon_name}} |
The icon’s name, e.g. check |
{{$icon_label}} |
Its label |
{{$icon_width}}, {{$icon_height}} |
Its size |
{{$icon_url}} lets you write your own markup around the icon:
<svg class="my-icon" width="32" height="32"><use href="{{$icon_url}}"></use></svg>
Colour#
Icons keep their own colours. The color option — or any CSS — makes them take the colour of the surrounding text instead:
.card__icon { color: #16a34a; } /* with the color option */
.my-icon { --wpc-icon-color: currentColor; color: #7c3aed; } /* your own <use> markup */
Inside icons.svg every solid fill and stroke reads var(--wpc-icon-color, <original colour>), so one file serves both: no variable → original colours; --wpc-icon-color: currentColor → the text colour. Gradients and transparent parts are kept.
Icons in the snippet’s own code#
Without an attribute, write the icon straight into the HTML: {{svg.check}}, {{svg.check.color}}, {{svg.check.inline}}. The Icons button in the snippet editor inserts them, typing {{ offers them, and the Live Preview shows them. They use the same icons.svg.
Uploads on another domain (CDN)#
Browsers follow <use> into a file only on the same domain as the page. If your uploads are served from a CDN on another domain, tick Embed the icons in pages instead on the Icons page: each page then carries the icons it uses at its end, like SVG Files do. Nothing else changes.
Icons with gradients, patterns or masks#
Safari cannot draw a gradient, pattern, mask, clip path or filter of an icon taken from a separate file. Icons that contain one are therefore always put into the page itself, at its end — whatever the embed setting; {{$icon_url}} is then #wpc-i-NAME, which works in your own <use> markup too. Simple one-colour icons keep using icons.svg.
When the full markup is printed#
The full SVG is printed instead of a reference with the inline option, and automatically where a reference cannot work: feeds, and when icons.svg cannot be written (the Icons page then says so).
Renaming, deleting, moving#
- The name is how snippets and blocks find an icon: renaming or deleting one empties every place that uses it. Edit an icon under the same name to change how it looks.
- Export / Import on the Icons page moves the library to another site; snippet exports also carry the icons their code uses with
{{svg.…}}. Blocks store icon names in your posts — import the library on the new site and they resolve again.
Which one to use?#
- Editors pick from a fixed set of icons used across the site → Icon.
- Editors upload their own artwork, or an image appears once → SVG File.
- The developer places a fixed icon in the snippet →
{{svg.name}}in the HTML.