# 为仅限访客的区域添加页眉链接

**URL:** https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546
**Category:** Support
**Created:** [2025 年9 月 4 日 08:52 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546 "2025-09-04T08:52:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![peternlewis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/peternlewis/32/108888_2.png) [@peternlewis](https://meta.discourse.org/u/peternlewis)
#### Post date: [2025 年9 月 4 日 08:52 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/1 "2025-09-04T08:52:40Z")

</div>

您好，

在经历了一次又一次的垃圾邮件攻击后，我已将我的论坛设置为仅限邀请加入，并在我的另一个网站上设置了一种自定义的、速率限制的发送邀请的方式。

我已将邀请系统的链接添加到了常见问题解答等地方，但我希望在用户未登录时，在“登录”链接旁边添加一个类似的自定义“创建账户”链接。

官方的 [`自定义标题链接`](https://meta.discourse.org/t/custom-header-links/90588) 似乎没有这个功能（除非我错过了什么）。

我尝试使用 `api.decorateWidget` 添加链接，但这会产生一个弃用警告，所以这显然不是正确的方法。

这表明我需要使用 `api.headerIcons.add(“foo”, FooIcon, { before: “search” })`，但如果我理解正确的话，`FooIcon` 是一种组件，而我不知道那是什么或者如何创建它。

所以基本上：我想在用户未登录时，在“登录”按钮旁边添加一个链接到特定 URL 的“创建账户”链接。我对主题或如何编辑它们知之甚少。

感谢您的任何帮助。

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [2025 年9 月 4 日 09:23 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/2 "2025-09-04T09:23:03Z")

</div>

> [@peternlewis](#):
>
> 官方的 [`Custom Header Links`](https://meta.discourse.org/t/custom-header-links/90588) 似乎没有这个功能（除非我错过了什么）。

我不确定你指的是什么没起作用：如果你只是需要添加一个链接，那么这里缺了什么？

编辑：像往常一样，Moin 比我看得更清楚 👀

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025 年9 月 4 日 09:32 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/3 "2025-09-04T09:32:38Z")

</div>

> [@peternlewis](#):
>
> 官方的 [`Custom Header Links`](https://meta.discourse.org/t/custom-header-links/90588) 似乎没有这个功能（除非我错过了什么）。

您可以使用自定义 CSS 隐藏使用该组件添加的链接，仅对已登录用户显示。

> [@Custom Header Links](https://meta.discourse.org/t/custom-header-links/90588/196):
>
> Hi, welcome! You can’t do it directly with the component, but you can use CSS to hide links. There is a .anon class you can rely on to determine whether a user is logged in. For example, if your link names are “Link 1” and “Link 2”: /\* Logged-out users \*/ html.anon .link-1-custom-header-links { display: none; } /\* Logged-in users \*/ html:not(.anon) .link-2-custom-header-links { display: none; } The HTML contains a class name where the link name is dasherized, followed by -custom-he…

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025 年9 月 4 日 13:06 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/4 "2025-09-04T13:06:08Z")

</div>

我还想起了 [https://meta.discourse.org/t/discourseconnect-signup-button/245888。但我觉得这只在你使用](https://meta.discourse.org/t/discourseconnect-signup-button/245888%E3%80%82%E4%BD%86%E6%88%91%E8%A7%89%E5%BE%97%E8%BF%99%E5%8F%AA%E5%9C%A8%E4%BD%A0%E4%BD%BF%E7%94%A8) [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) 时才有效。

---

<div class="post-metadata">

### Author: ![peternlewis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/peternlewis/32/108888_2.png) [@peternlewis](https://meta.discourse.org/u/peternlewis)
#### Post date: [2025 年9 月 5 日 02:30 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/5 "2025-09-05T02:30:41Z")

</div>

那听起来就是解决方案了。  
我会在试过之后汇报结果。  
谢谢！

---

<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: [2025 年10 月 5 日 02:31 UTC](https://meta.discourse.org/t/adding-a-header-link-for-guests-only/381546/6 "2025-10-05T02:31:30Z")

</div>

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