# Admin only button in header?

**URL:** https://meta.discourse.org/t/admin-only-button-in-header/98732
**Category:** Support
**Created:** [October 4, 2018, 4:01pm UTC](https://meta.discourse.org/t/admin-only-button-in-header/98732 "2018-10-04T16:01:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![shaundefense](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shaundefense/32/119563_2.png) [@shaundefense](https://meta.discourse.org/u/shaundefense)
#### Post date: [October 4, 2018, 4:01pm UTC](https://meta.discourse.org/t/admin-only-button-in-header/98732/1 "2018-10-04T16:01:03Z")

</div>

I want to add a button to the header of my site that is only visible to admins. Is this possible? Does discourse have conditional code snippets?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 4, 2018, 9:37pm UTC](https://meta.discourse.org/t/admin-only-button-in-header/98732/2 "2018-10-04T21:37:13Z")

</div>

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 `admin` class is present:

```plaintext
<script type="text/discourse-plugin" version="0.8.23">
let currentUser = api.getCurrentUser();
if (currentUser && currentUser.admin) {
    $('body').addClass('admin');
}
</script>

```

If hiding the button with CSS isn’t secure enough for your use case, you will need to do something a little more involved to insert the button with javascript.

---

<div class="post-metadata">

### Author: ![shaundefense](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/shaundefense/32/119563_2.png) [@shaundefense](https://meta.discourse.org/u/shaundefense)
#### Post date: [October 4, 2018, 10:41pm UTC](https://meta.discourse.org/t/admin-only-button-in-header/98732/3 "2018-10-04T22:41:20Z")

</div>

That was exactly what I needed! Thank you!

---

<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: [November 3, 2018, 10:42pm UTC](https://meta.discourse.org/t/admin-only-button-in-header/98732/4 "2018-11-03T22:42:13Z")

</div>

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