# 在头部添加一个注册按钮（Memberful购买链接），登录后隐藏

**URL:** <https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537>\
**Category:** Support\
**Created:** [2018年二月26日 13:10 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537 "2018-02-26T13:10:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francois\_Douville](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/francois_douville/32/94221_2.png) [@Francois\_Douville](https://meta.discourse.org/u/Francois_Douville)\
**Post date:** [2018年二月26日 13:10 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537/1 "2018-02-26T13:10:38Z")

</div>

I have the memberful integration with Discourse. When SSO is active, the sign up button disappear. Only the “sign in” button of Discourse is showing and convert to the Memberful’s sign in form.

I will add a “sign up” button with some CSS codes in the header. My question is : how to make this button disappear when a member is log in? I want the same thing that happen to the current “sign in” button of Discourse, it is hiding when a member log in.

---

<div class="post-metadata">

**Author:** ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)\
**Post date:** [2018年二月26日 13:50 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537/2 "2018-02-26T13:50:56Z")

</div>

Just make it appear only to users not logged in using the `.anon` class, take a look here as example [Banner Topic on home page and only for anonymous users](https://meta.discourse.org/t/banner-topic-on-home-page-and-only-for-anonymous-users/80959)

---

<div class="post-metadata">

**Author:** ![Francois\_Douville](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/francois_douville/32/94221_2.png) [@Francois\_Douville](https://meta.discourse.org/u/Francois_Douville)\
**Post date:** [2018年二月26日 22:39 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537/3 "2018-02-26T22:39:30Z")

</div>

Thanks! It is working perfectly!

---

<div class="post-metadata">

**Author:** ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)\
**Post date:** [2018年三月28日 00:13 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537/4 "2018-03-28T00:13:46Z")

</div>

A note for future readers.

The approach mentioned by @dax works fine, however another approach you can take to add a Sign Up button when SSO is active is to use the plugin api in a header script.

The advantage of using the plugin api is that you can insert the button in the right part of the DOM tree to make styling easier.

This issue arose in the context of getting @Francois_Douville’s button to play nicely with the Header Search Theme ([see here](https://meta.discourse.org/t/header-search-theme/67959/27)).

In @Francois_Douville’s case, the appropriate javascript to add the button is:

```plaintext
<script type="text/discourse-plugin" version='0.8.12'>
api.decorateWidget('header-buttons:before', function (helper) {
    if (!api.getCurrentUser()) {
        let rawLabel = helper.widget.site.mobileView ? "S'inscrire" : "S'inscrire gratuitement";
        return helper.attach('link', {
            href: 'https://lepeuplier.memberful.com/checkout?plan=27167',
            rawLabel,
            className: "btn btn-primary btn-small login-button"
        });
    }
});
</script>

```

---

<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:** [2024年六月8日 12:37 UTC](https://meta.discourse.org/t/add-a-sign-up-button-memberful-purchase-link-in-header-and-disappear-when-log-in/81537/5 "2024-06-08T12:37:40Z")

</div>

此主题已在 2293 天后自动关闭。不再允许回复。
