# Show BUTTON only to staff users

**URL:** https://meta.discourse.org/t/show-button-only-to-staff-users/149552
**Category:** Support
**Created:** [April 28, 2020, 6:08am UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552 "2020-04-28T06:08:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ed\_Bobkov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_bobkov/32/200014_2.png) [@Ed\_Bobkov](https://meta.discourse.org/u/Ed_Bobkov)
#### Post date: [April 28, 2020, 6:08am UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552/1 "2020-04-28T06:08:06Z")

</div>

I added some button via script in the `<head>...</head>` part at this page:  
`/admin/customize/themes/2/common/head_tag/edit`

this way  
`<script type="text/discourse-plugin" version="0.4">`  
`api.onToolbarCreate(toolbar => {`  
`toolbar.addButton({`  
`id: "times-circle",`  
`});`  
`});`  
`</script>`

How can I make this button be visible only to staff users (moderators, admin) and users in group called “vip-group”?

---

<div class="post-metadata">

### Author: ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)
#### Post date: [April 28, 2020, 7:43am UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552/2 "2020-04-28T07:43:04Z")

</div>

Hi! Simple as this

```plaintext
<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();

// find if user is in vip-group
const isInVipGroup = user.groups.some(({name}) => name === "vip-group");

if (user.staff || isInVipGroup) {
  api.onToolbarCreate(toolbar => {
    toolbar.addButton({
      id: "times-circle",
    });
  });
}
</script>
```

---

<div class="post-metadata">

### Author: ![Ed\_Bobkov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_bobkov/32/200014_2.png) [@Ed\_Bobkov](https://meta.discourse.org/u/Ed_Bobkov)
#### Post date: [April 28, 2020, 7:50am UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552/3 "2020-04-28T07:50:29Z")

</div>

Great! It’s working!  
Also I found these topics, that may be userful for smbd.

> [@Admin only button in header?](https://meta.discourse.org/t/admin-only-button-in-header/98732/2):
>
> Discourse adds a staff class to the body tag when a staff user is viewing the site. If you are ok with the button being visible to admins and moderators, you could hide the button with CSS and then make it visible when the staff class is present. If only having the button visible to admins is a requirement, you will need to use some javascript to determine that the user is an admin. The easiest approach to that would be to add an admin class to the body and then make the button visible when the…

> [@Show custom HTML in header to member of a specific group](https://meta.discourse.org/t/show-custom-html-in-header-to-member-of-a-specific-group/142974/3):
>
> \<div id="after-header"\>Stuff\</div\> \<script type="text/discourse-plugin" version="0.8"\> api.onPageChange(() =\> { let currentUser = api.getCurrentUser(); var groups = currentUser.groups; const isInGroup1 = groups.some(g =\> g.name === 'group1'); const isInGroup2 = groups.some(g =\> g.name === 'group2'); const isInGroup3 = groups.some(g =\> g.name === 'group3'); if (isInGroup1) { $("#after-header").addClass("group1"); } …

---

<div class="post-metadata">

### Author: ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)
#### Post date: [April 28, 2020, 7:51am UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552/4 "2020-04-28T07:51:33Z")

</div>

@Ed_Bobkov I’ve edited snippet to work for your certain group type. Don’t know if you have seen that, just a reminder.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [July 31, 2020, 8:17pm UTC](https://meta.discourse.org/t/show-button-only-to-staff-users/149552/5 "2020-07-31T20:17:22Z")

</div>

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