# Hide full name if not logged in

**URL:** https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789
**Category:** Development
**Created:** [4월 11, 2019, 5:26오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789 "2019-04-11T17:26:50Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![DubZ](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DubZ](https://meta.discourse.org/u/DubZ)
#### Post date: [4월 11, 2019, 5:26오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/1 "2019-04-11T17:26:50Z")

</div>

Hi,

my current configuration is, that discourse is readable if you are not logged in. Also I set “enable names” to see the full name right near the nick name.

But what I DONT want is, that not logged in users can see the full name. Is there any way to disable this? I didnt found it.

Thx in advance for your help!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [4월 11, 2019, 11:22오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/2 "2019-04-11T23:22:20Z")

</div>

Is this possible with CSS @tshenry? I think we have the anon classes to do it?

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [4월 11, 2019, 11:44오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/3 "2019-04-11T23:44:46Z")

</div>

I was going to respond to this earlier with some CSS, but remembered the case where username and display name match, resulting in the username being hidden.

In that situation it would present an avatar, with no name whatsoever.

---

<div class="post-metadata">

### Author: ![DubZ](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DubZ](https://meta.discourse.org/u/DubZ)
#### Post date: [4월 12, 2019, 12:28오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/7 "2019-04-12T00:28:15Z")

</div>

> [@Stephen](#):
>
> In that situation it would present an avatar, with no name whatsoever

But still better than get crawled by any bots 🙂 other forum software (plug-ins) hiding the full name and also anonymze the nick in e.g. to “user 34726”. Would be really perfect if I could hide at least the real name 🙂

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [4월 12, 2019, 12:31오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/8 "2019-04-12T00:31:39Z")

</div>

I’m going to look into this when I get a chance. It should be doable with a small theme component. I’ve got a decent amount on my plate, so it maybe be a little bit before I get back to you with anything.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [4월 13, 2019, 3:43오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/9 "2019-04-13T03:43:26Z")

</div>

Alright, the script for removing the full name for anons is fairly simple. Just create a new theme component and add the following to the Common `</head>` section:

```plaintext
<script type="text/discourse-plugin" version="0.8">
  api.reopenWidget("poster-name", {
    html(attrs) {
      let contents = this._super(attrs);
      if(contents.length == 2 && !api.getCurrentUser()) {
        return contents.shift();
      }
      return contents;
    }
  });
</script>

```

Some things to note:

- To better avoid full names getting out, it would be best to set the site setting `hide_user_profiles_from_public`
- This code assumes you have `prioritize_username_in_ux` enabled
- A user’s full name will be used as the title attribute for a user avatar, so it will be displayed whenever someone hovers over an avatar. I haven’t found a solution for this yet, but I’ll come back if one is found.

Hope that helps 🙂

---

<div class="post-metadata">

### Author: ![DavidO](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@DavidO](https://meta.discourse.org/u/DavidO)
#### Post date: [7월 24, 2019, 2:18오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/10 "2019-07-24T02:18:50Z")

</div>

Did this ever get integrated?

We’d like our forums to be publicly readable and indexed by search engines, but we’d like to not show real names unless you’re logged in (so that people’s real names aren’t exposed to non-members and search engines).

Is that possible? I tried the above code and could not get it working.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [7월 24, 2019, 3:28오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/11 "2019-07-24T03:28:05Z")

</div>

Does the above code need an update @tshenry?

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [7월 24, 2019, 11:16오전 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/13 "2019-07-24T11:16:36Z")

</div>

I just checked and the code still works. All of the notes I mention still apply.

* * *

I did try to track down all of the areas where the user’s full name was used as the title attribute of their avatar. The following code should cover all the areas assuming you have `hide_user_profiles_from_public` and `prioritize_username_in_ux` enabled. Unfortunately it relies on overriding a couple of templates, but they don’t change very often. I’ve included links to the files on GitHub if you ever want to check to see if you need to update any of the code. The only modification I made was either adding or changing the `namePath` so that it uses the username instead of the full name.

```plaintext
<script type="text/discourse-plugin" version="0.8">
  api.reopenWidget("poster-name", {
    html(attrs) {
      let contents = this._super(attrs);
      if(contents.length == 2 && api.getCurrentUser()) {
        return contents.shift();
      }
      return contents;
    }
  });
  
  api.reopenWidget("post-avatar", {
    html(attrs) {
      attrs.name = "";
      return this._super(attrs);
    }
  });
  
  api.reopenWidget("topic-map-summary", {
    html(attrs, state) {
      attrs.createdByName = "";
      attrs.lastPostName = "";
      return this._super(attrs, state);
    }
  });
  
  api.reopenWidget("topic-participant", {
    html(attrs, state) {
      attrs.name = "";
      return this._super(attrs, state);
    }
  });

</script>

<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/user-info.hbs -->
<script type="text/x-handlebars" data-template-name="components/user-info">
  <div class="user-image">
    <div class="user-image-inner">
      <a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{avatar user namePath="user.username" imageSize="large"}}</a>
      {{#if user.primary_group_name}}
        {{avatar-flair
          flairURL=user.primary_group_flair_url
          flairBgColor=user.primary_group_flair_bg_color
          flairColor=user.primary_group_flair_color
          groupName=user.primary_group_name}}
      {{/if}}
    </div>
  </div>

  <div class="user-detail">
    <div class='name-line'>
      <span class="username"><a href="{{unbound userPath}}" data-user-card="{{unbound user.username}}">{{format-username user.username}}</a></span>
      <span class="name">{{unbound name}}</span>
    </div>
    <div class="title">{{unbound user.title}}</div>

    {{#if hasBlock}}
      <div class='details'>
        {{yield}}
      </div>
    {{/if}}

  </div>
</script>

<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs -->
<script type="text/x-handlebars" data-template-name="list/posters-column.raw">
  <td class='posters'>
  {{#each posters as |poster|}}
  <a href="{{poster.user.path}}" data-user-card="{{poster.user.username}}" class="{{poster.extraClasses}}">{{avatar poster avatarTemplatePath="user.avatar_template" usernamePath="user.username" namePath="user.username" imageSize="small"}}</a>
  {{/each}}
  </td>
</script>

<!-- https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/latest-topic-list-item.hbs -->
<script type="text/x-handlebars" data-template-name="components/latest-topic-list-item">
  <div class='topic-poster'>
    {{#user-link user=topic.lastPoster}}
      {{avatar topic.lastPoster namePath="topic.lastPoster" imageSize="large"}}
    {{/user-link}}
  </div>
  <div class='main-link'>
    <div class='top-row'>
      {{raw "topic-status" topic=topic}}
      {{topic-link topic}}
      {{#if topic.featured_link}}
        {{topic-featured-link topic}}
      {{/if}}
      {{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}}
    </div>
    <div class='bottom-row'>
      {{category-link topic.category}}
      {{discourse-tags topic mode="list"}}
    </div>
  </div>
  <div class='topic-stats'>
    {{raw "list/posts-count-column" topic=topic tagName="div"}}
    <div class="topic-last-activity">
      <a href="{{topic.lastPostUrl}}" title="{{topic.bumpedAtTitle}}">{{format-date topic.bumpedAt format="tiny" noTitle="true"}}</a>
    </div>
  </div>
</script>

```

This shouldn’t be viewed as a 100% secure method, but it will keep the information out of sight from anyone that’s not trying hard to find it.

At some point it would be nice to have this functionality as core behavior whenever `prioritize_username_in_ux` is enabled.

@DavidO have you read through [Beginner's guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966#heading--2-3)? If you created a theme component and added the code to the Common `</head>` section, be sure to add the component to your main theme.

---

<div class="post-metadata">

### Author: ![DavidO](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@DavidO](https://meta.discourse.org/u/DavidO)
#### Post date: [7월 24, 2019, 2:03오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/14 "2019-07-24T14:03:51Z")

</div>

OK, thanks. Will work on it some more.

Agree that it would be nice to have it as an option, to hide real name from people not logged in (including search engines).

Appreciate it fellas.

---

<div class="post-metadata">

### Author: ![tomtjes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tomtjes/32/131271_2.png) [@tomtjes](https://meta.discourse.org/u/tomtjes)
#### Post date: [3월 13, 2020, 5:16오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/15 "2020-03-13T17:16:47Z")

</div>

커뮤니티의 일부 내용을 공개하는 것을 고려하고 있습니다. 해당 카테고리에 기여한 멤버들을 보호하기 위해, 이와 유사한 익명화 스크립트를 사용하고자 합니다. 다만, prioritize\_username\_in\_ux를 활성화하고 싶지는 않습니다. 대신, 사용자 이름과 실명, 그리고 아바타까지 모두 흐릿하게 처리하는 것은 괜찮습니다. 스크립트를 수정하여 이 기능을 구현할 수 있는 방법이 있을까요?

---

<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: [3월 5, 2024, 1:59오후 UTC](https://meta.discourse.org/t/hide-full-name-if-not-logged-in/114789/16 "2024-03-05T13:59:58Z")

</div>


