How to create a theme which only administrators can use?

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:

<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:

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

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

3 Likes