How to change moderator icon

Hey, I read through this: Replace Discourse's default SVG icons with custom icons in a theme

Created a spritesheet (I think I have done this correctly):

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
    <symbol id="mod-crown" width="13" height="11" viewBox="0 0 13 11">
        <metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
            <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c142 79.160924, 2017/07/13-01:06:39        ">
                <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
                    <rdf:Description rdf:about=""/>
                </rdf:RDF>
            </x:xmpmeta>
            <?xpacket end="w"?></metadata>
        <defs>
            <style>
                .cls-1 {
                fill: #04b214;
                }

                .cls-1, .cls-2, .cls-3, .cls-4 {
                fill-rule: evenodd;
                }

                .cls-3 {
                fill: #29ec3a;
                }

                .cls-4 {
                fill: #1f8111;
                }
            </style>
        </defs>
        <path class="cls-1" d="M11,5V3h1V5H11ZM10,7v3H9V7H7V8H6V7H4v3H3V7H2V5H5V3H6V1H7V3H8V5h3V7H10ZM8,10H7V8H8v2ZM5,10V8H6v2H5ZM1,3H2V5H1V3Z"/>
        <path class="cls-2" d="M8,10V8H7V7H9v3H8ZM6,10V8H7v2H6ZM5,10H4V7H6V8H5v2Z"/>
        <path class="cls-3" d="M11,3V1h1V3H11ZM10,5V3h1V5H10ZM4,5V3H5V5H4ZM5,1H6V3H5V1ZM2,7H3v3H2V7ZM1,5H2V7H1V5ZM0,1H1V5H0V1Z"/>
        <path class="cls-4" d="M12,5V0h1V5H12ZM11,7V5h1V7H11Zm0,4H2V10h8V7h1v4ZM8,3H9V5H8V3ZM7,1H8V3H7V1ZM6,0H7V1H6V0ZM2,3H3V5H2V3ZM1,1H2V3H1V1ZM0,0H1V1H0V0Z"/>
    </symbol>
</svg>

Added the asset to about.json:

    "assets": {
        "mod-crown": "assets/mod-crown.svg"
    }

And added this to header.html:

<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('d-icon-shield-halved', 'mod-crown');
</script>

But the icon is not changed, the shield icon remains. What am I doing wrong?

1 Like

Hi, welcome!

The mod-crown variable name should be replaced by icons-sprite.

I had the same issue before, I think the documentation could be improved in this bit.


Also,

It should be: api.replaceIcon('shield-halved', 'mod-crown');

1 Like

I’ve adjusted this but there has been no change.

    "assets": {
        "icons-sprite": "assets/mod-crown.svg"
    }

Is my spritesheet valid? I notice it looks different than other spritesheets e.g. assets/spritesheet.svg · main · Manuel Kostka / Discourse / Themes / Heroes · GitLab

I tried removing style="display: none;" from the svg tag in my spritesheet but that did not help either.

Did you try to remove the metadata, just in case?

Let me give it a try on my side.

No change when removing metadata.

However:

<script type="text/discourse-plugin" version="0.8">
    api.replaceIcon('shield-alt', 'mod-crown');
</script>

This gets it to show up but I also get a scary warning about compatibility:

In the inspector I get this warning: Deprecation notice: The icon name "shield-alt" has been updated to "shield-halved".

And using shield-halved instead of d-icon-shield-halved works properly!

Thanks for your help :grin:

2 Likes

What I was about to say, just noticed it as well!

I’m glad it works. :grinning_face_with_smiling_eyes:

1 Like