How to hide a button (SVG icon) if user is logged in?

Hi. How can I hide a button (it’s really a SVG icon that links to something), only when someone is logged into an account, though?

1 Like

You could use the .anon class and do it similar to this:

2 Likes

You have a anon class attached to the <html> tag.

So you can use like:

html:not(.anon) .your_svg_selector {
   display: none;
}
2 Likes

@omarfilip @Arkshine And this will make it so that this icon is hidden from logged in users only? Also, where exactly is that anon class? I can’t seem to find it.

Yes.

Ah, sorry - you wanted the opposite, so: not(.anon)

3 Likes

Ahah, I totally read the wrong way as well, my bad!

Oh, so it has to manually be added somehow? Mine just has:
class="desktop-view not-mobile-device text-size-normal no-touch discourse-no-touch"

There is nothing to add. Discourse automatically applies an “anon” class if you are not logged in. So you can have a CSS saying, “If anon class is not present…”.

1 Like

This is all the stuff that links to the icon I want hidden. Which part here is the “selector”? :open_mouth:

Yes, you will need to customize your site’s css:

2 Likes

@45thj5ej .header-icon-login .d-icon-user should be okay.

1 Like

Ok, cool, and I just place this in my CSS code?

HTML:not(.anon) .header-icon-login .d-icon-user {
   display: none;
}
1 Like
html:not(.anon) .header-icon-login .d-icon-user {
   display: none;
}

You can put in your theme CSS (if available) or, better, a theme component CSS attached to your theme.

1 Like

Ah, shoot. So, it worked, but when it gets hidden, it doesn’t slide the icon to the left of it over, so there’s a weird gap. Is there a way to make it without the gap, but without moving the order of the icons?
yyyy

1 Like

Try this, to include the <li>.

html:not(.anon) .header-icon-login  {
   display: none;
}
4 Likes

Dude, thank you so much. :pray:

2 Likes

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