# How to create a theme which only administrators can use?

**URL:** https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500
**Category:** Development
**Created:** [June 15, 2023, 5:46pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500 "2023-06-15T17:46:11Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 15, 2023, 5:46pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/1 "2023-06-15T17:46:11Z")

</div>

How to create a theme, not which only administrators can use?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 15, 2023, 5:57pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/2 "2023-06-15T17:57:26Z")

</div>

I’m not sure I know what you mean. Could you go into a little more detail?

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 15, 2023, 7:18pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/3 "2023-06-15T19:18:58Z")

</div>

A lot of problems happen in my forum, I already commented here on meta about it, and as I couldn’t disable the moderators dangerous functions, because the Discourse doesn’t have that option, I made a kludge through CSS, to remove the options that are dangerous for my forum in which they have access , when I did it via CSS it turned out that it was taken from me too, options like see IP, ban, delete all posts etc… I took it out of all themes, I would like to leave only one theme without CSS so I can see the options, but that only I can use this theme

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [June 15, 2023, 7:34pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/4 "2023-06-15T19:34:21Z")

</div>

i don’t know why you are using CSS and themes to manage your moderators, but, that’s not how you do it. use trust levels to make category mods and also choose your mods more carefully. you are likely just creating more problems for yourself by trying to limit moderator functions via CSS and themes.

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 15, 2023, 7:50pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/5 "2023-06-15T19:50:19Z")

</div>

I solved all my problems by modifying my moderators roles via CSS. It’s a very complex situation and the only real solution was this. I already tried category moderation and it was not viable for my forum, it was not interesting for the demand. The only way that solved my problems was the modifications via CSS. As Discourse leaves the same moderator options to admin, this was the only solution. But now I just need a way for me to be able to use a theme that doesn’t have CSS modifications. So I don’t have to turn it off every time I use it.

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 15, 2023, 7:54pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/6 "2023-06-15T19:54:49Z")

</div>

I’m going to tell you a little bit about what happened: I live in Brazil, here there are 214.3 million inhabitants, most of them unemployed and without purchasing power. A lot of people use the internet as a means of entertainment, so my forum fits that. But the existence of my forum threatens another forum a lot, which has already made NUMEROUS attacks on mine, and has already bought a lot of my moderators, countless moderators have already deleted users, deleted messages, leaked IPs to others, really destroyed me. I’ve already spent months without any moderators, but it’s very difficult to have a forum without a moderator, I want to put moderators back, but it’s no use choosing well, I don’t know how the culture of the Nordic countries is, but at least in the culture of the sector from forums in my country, people don’t take it very seriously and are easily corrupted, one time or another money talks louder and they can use their powers to destroy my forum, the only solution I have is that the moderators don’t have the same powers as administrators, and that was the only thing that solved it, through CSS.

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 15, 2023, 7:56pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/7 "2023-06-15T19:56:56Z")

</div>

I had already made a topic about this, which started a big debate that went nowhere, many advised me to choose moderators better, so I could have a sense of criteria and choose more reliable people, well, but that doesn’t apply to the world forums I’m on, the only solution was to take some powers away from the moderators (IP, Ban, Delete all posts, check email etc) but that affected me too.

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [June 15, 2023, 9:36pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/8 "2023-06-15T21:36:20Z")

</div>

Hello 👋

You can use [Safe Mode](https://meta.discourse.org/t/53504?silent=true) _(just like your moderators)_ to disable themes.

With custom sections you can make your quick route to `/safe-mode`

1. Create a custom section to your sidebar like this.  

2. It will place in the Navigation Menu (sidebar) custom section.  

3. Here you can disable the themes and theme components. Click Enter [Safe Mode](https://meta.discourse.org/t/53504?silent=true) button.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 15, 2023, 11:33pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/9 "2023-06-15T23:33:53Z")

</div>

Maybe check out category moderators?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [June 16, 2023, 4:52am UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/10 "2023-06-16T04:52:20Z")

</div>

If a bad actor discovers [safe mode](https://meta.discourse.org/t/53504?silent=true) your CSS countermeasures will be ineffective.

The only way to secure Discourse is by careful assignment of privileges via the back end.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 16, 2023, 5:31am UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/11 "2023-06-16T05:31:28Z")

</div>

> [@merefield](#):
>
> The only way to secure Discourse is by careful assignment of privileges via the back end.

That is to say that you would need a custom plugin that made those changes. Unless you have a budget (maybe $1000 to $5000?) , you’ll need to try category moderators or tl4.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [June 16, 2023, 7:32am UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/12 "2023-06-16T07:32:37Z")

</div>

They already talked about it here: 🙂

> [@danielabc](#):
>
> I already tried category moderation and it was not viable for my forum, it was not interesting for the demand.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 16, 2023, 11:14am UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/13 "2023-06-16T11:14:26Z")

</div>

I think it should be possible to make the theme component hide the stuff for everyone except for admins.

But [safe mode](https://meta.discourse.org/t/53504?silent=true) would still be an easy bypass. Maybe a quick and dirty plugin could disable those features without as much time as I originally estimated.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [June 16, 2023, 11:36am UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/14 "2023-06-16T11:36:07Z")

</div>

I agree with pretty much everything everyone has said here.

If you really want to go the CSS way, here’s how you can make your CSS modifications only apply to non-admins:

In the `Head` tab of your theme, write this:

```js
<script type="text/discourse-plugin" version="1.4.0">
    let currentUser = api.getCurrentUser();
    if (currentUser.admin == true) {
         document.querySelector("body").classList.add("is-admin");
    }
</script> 

```

Wrap **all** your CSS rules with `body:not(.is-admin) {` (your CSS) `}` such as:

```css
body:not(.is-admin) {
    #main {
        background: pink;
    }
}

```

In my example, the pink background will be applied to everyone but the admin users.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [June 16, 2023, 12:38pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/15 "2023-06-16T12:38:06Z")

</div>

~~Discourse automatically adds group-based classes to the `<body>` so it should be possible to skip the JS and do something like~~

~~`body:not(.group-admins) #main { background: pink; }`~~

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [June 16, 2023, 1:10pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/16 "2023-06-16T13:10:37Z")

</div>

> [@david](#):
>
> Discourse automatically adds group-based classes to the `<body>` so it should be possible to skip the JS and do something like

I don’t have other group-specific class than `staff` as an admin on my test instance (last Discourse version):

`<body class="chat-enabled staff has-sidebar-page navigation-topics docked"`

As far as I can see, neither in `<html>` nor any other tag.

On meta, we use [CSS Classes for Current User's Groups](https://meta.discourse.org/t/css-classes-for-current-users-groups/226068), which could also be used in daniela’s case. 🙂

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [June 16, 2023, 1:16pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/17 "2023-06-16T13:16:02Z")

</div>

> [@Canapin](#):
>
> On meta, we use [CSS Classes for Current User’s Groups](https://meta.discourse.org/t/css-classes-for-current-users-groups/226068), which could also be used in daniela’s case. 🙂

Ahhhhh that’s what confused me - I was just looking on Meta 🤦‍♂️ Thanks @Canapin

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [June 17, 2023, 4:52pm UTC](https://meta.discourse.org/t/how-to-create-a-theme-which-only-administrators-can-use/268500/18 "2023-06-17T16:52:05Z")

</div>

I LOVE YOU SO MUCH

Thank you for showing me this, I couldn’t solve this problem for more than 1 year
