# Display Header HTML to Logged-in Users Only

**URL:** https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806
**Category:** Support
**Created:** [April 8, 2019, 9:52pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806 "2019-04-08T21:52:16Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![DigitalStartup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/digitalstartup/32/118242_2.png) [@DigitalStartup](https://meta.discourse.org/u/DigitalStartup)
#### Post date: [April 8, 2019, 9:52pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/1 "2019-04-08T21:52:16Z")

</div>

If I write a snippet of code in the Header (i.e. a banner or advertisement message), is there a way to wrap the code in something that ensures it only gets display to logged in users?

---

<div class="post-metadata">

### Author: ![daxen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daxen/32/64364_2.png) [@daxen](https://meta.discourse.org/u/daxen)
#### Post date: [April 8, 2019, 9:59pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/2 "2019-04-08T21:59:42Z")

</div>

hi,

I’m looking for something similar.  
i want to show a static html menu at the top, which should only be visible for registered users.

I would be interested in a solution too.

best regards,  
Daniel.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 8, 2019, 10:33pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/3 "2019-04-08T22:33:59Z")

</div>

Perhaps like this - wrap it in a div, i.e. `logged_in_content` and hide it from users who are not logged in:

```
html.anon div#logged_in_content {
  display: none;
}

```

as mentioned by @Falco:

> [@Display banner topic only to logged in users?](https://meta.discourse.org/t/display-banner-topic-only-to-logged-in-users/55282/2):
>
> Add the banner topic and hide it with CSS, the html.anon selector can hide it from non logged users.

---

<div class="post-metadata">

### Author: ![daxen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daxen/32/64364_2.png) [@daxen](https://meta.discourse.org/u/daxen)
#### Post date: [April 9, 2019, 12:29am UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/4 "2019-04-09T00:29:15Z")

</div>

I don’t want to hide it.  
i want to deliver the html block to registered users only.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 9, 2019, 2:30am UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/5 "2019-04-09T02:30:29Z")

</div>

This will display it to those who are logged in and hide for those who are not.

---

<div class="post-metadata">

### Author: ![daxen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daxen/32/64364_2.png) [@daxen](https://meta.discourse.org/u/daxen)
#### Post date: [April 9, 2019, 10:28am UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/6 "2019-04-09T10:28:23Z")

</div>

yes, i know how css works 😉

but this is no solution.

> [@daxen](#):
>
> i want to deliver the html block to registered users only.

i dont want that not logged in users can see the html in page-source or it can be indexd by search engines.

its a closed forum and hiding with css is no solution.

i already tried this in the admin backend:  
[https://meta.discourse.org/t/adding-plugin-outlets-using-a-theme/32727/12](https://meta.discourse.org/t/adding-plugin-outlets-using-a-theme/32727/12)

but without success.  
the script tag an inner-html is not published.

---

<div class="post-metadata">

### Author: ![DigitalStartup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/digitalstartup/32/118242_2.png) [@DigitalStartup](https://meta.discourse.org/u/DigitalStartup)
#### Post date: [April 9, 2019, 7:45pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/7 "2019-04-09T19:45:57Z")

</div>

Can something similar be done for hiding HTML from certain **Groups**? Or is a simple CSS solution too much to ask for this?

**Edit:** I misspoke. I didn’t mean individuals, just **Groups**. @pmusaraj @omarfilip

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [April 9, 2019, 7:51pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/8 "2019-04-09T19:51:42Z")

</div>

Search meta for either “currentUser” or “api.getCurrentUser” and you should see several code examples. You can use this to determine whether a user is loggedin, and then act accordingly.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 9, 2019, 7:55pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/9 "2019-04-09T19:55:07Z")

</div>

Check if this method is still valid:

> [@CSS classes for group membership? (For simplified UI mode)](https://meta.discourse.org/t/css-classes-for-group-membership-for-simplified-ui-mode/60838/2):
>
> There might be something that exists in Discourse already - but I personally don’t know of it… Here is some code I wrote a long time ago and it still appears to work… … however there is probably a far better way. It may / may not help you. For a specific username \<script\> if (window.jQuery) { window.jQuery(function ($) { var u = Discourse.User.current(); if (u && (u.username === 'DeanMarkTaylor' || u.username === 'BobTheBuilder')) { // Here is where you could add a C…

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 9, 2019, 10:29pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/10 "2019-04-09T22:29:16Z")

</div>

> [@DigitalStartup](#):
>
> **Edit:** I misspoke. I didn’t mean individuals, just **Groups**.

I’m not sure, but explore this topic:

> [@I want to customize UI based on the users group membership](https://meta.discourse.org/t/i-want-to-customize-ui-based-on-the-users-group-membership/83786):
>
> This reminds me that the issue of wanting to customize the UI based on the users membership in groups has come up in various forms before (can’t find too many topics though, so maybe it was just in my head). For example: And then there is, of course, the “Click me” button plugin: Also: In more general terms, this means that on certain forums groups distinguish quite different user groups (esp. on those forums where setting up different discourse instances was an option). So the question …

---

<div class="post-metadata">

### Author: ![daxen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daxen/32/64364_2.png) [@daxen](https://meta.discourse.org/u/daxen)
#### Post date: [April 10, 2019, 10:30am UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/11 "2019-04-10T10:30:57Z")

</div>

this is a good solution, I have tested, but unfortunately not what I am looking for.

I’m looking for a server side solution, not a client side (css/js) solution.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [April 10, 2019, 1:34pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/12 "2019-04-10T13:34:00Z")

</div>

Why do you have to have a server-side solution? Discourse is a full JS app, all of the header components for example have their html generated in JS. You can write the group-specific html in JS, and it will never be displayed to non-group users.

---

<div class="post-metadata">

### Author: ![daxen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daxen/32/64364_2.png) [@daxen](https://meta.discourse.org/u/daxen)
#### Post date: [April 10, 2019, 2:31pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/13 "2019-04-10T14:31:03Z")

</div>

> [@pmusaraj](#):
>
> Why do you have to have a server-side solution?

because my html content i want to show is only for logged-in users.

with this js solution every not logged in user can access the .js file over the url which is included always (in the login page too)

> http\_s://forum.domain.tld/theme-javascripts/83c1451748e441c882ef44430f033c57bb1ab1dd.js

and can see my js-injected html thats only for logged-in users.

i need a secure solution, not css/js pseudo secure solution.

---

<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: [May 10, 2019, 2:42pm UTC](https://meta.discourse.org/t/display-header-html-to-only-logged-in-users/113806/14 "2019-05-10T14:42:06Z")

</div>

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