로그인 사용자를 위한 헤더에 추가 버튼

로그인한 사용자만 헤더에 버튼을 추가하는 방법은 무엇인가요? 이 버튼에는 사용자 정의 텍스트와 링크를 추가해야 합니다.

Customization > Theme component 카테고리를 검색해서 이미 필요에 맞는 것이 있는지 확인해 보셨나요?

로그인한 사용자만 표시하기

익명 사용자를 대상으로 하여 요소가 그들에게 표시되지 않도록 할 수 있습니다. 예를 들어, 다음 코드는 로그인하지 않은 사용자에게 내비게이션 사이드바 메뉴의 태그를 숨깁니다. 비슷한 코드를 사용하여 헤더의 어떤 요소든 익명 사용자에게 숨길 수 있습니다.

.anon .sidebar-section-wrapper.sidebar-section[data-section-name="tags"] {
    display: none; 
}

정말 좋은 해결책입니다.

저는 사실 상단에 버튼 하나만 넣고 싶었거든요.

결국 ChatGPT에게 코드로 수동으로 추가하는 방법을 물어봤더니 작동하는 해결책을 주더라고요…

Header:

<script type="text/discourse-plugin" version="0.8.22">
api.decorateWidget('header-buttons:after', helper => {
    let currentUser = api.getCurrentUser();
    if (!currentUser) return; 
    
    return helper.h('li.custom-login-button-li', [
        helper.h('a.custom-login-button', { href: 'ENTER URL HERE', target: '_blank'}, 'Button')
    ]);
});
</script>

CSS

.custom-login-button {
    display: inline-block;
    margin: 0;
    padding: 0.5em 1em;
    text-align: center;
    vertical-align: middle;
    border: 1px solid transparent;
    font-weight: bold;
    line-height: 1.5;
    border-radius: 3px;
    color: #fff !important;
    background-color: #0084ff;
    border-color: #0076e6;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.custom-login-button:hover {
    background-color: #0076e6;
    border-color: #0065d0;
}

.custom-login-button-li {
    list-style-type: none;
}

좋은 작업이네요, @Sami_Syed.

저는 포럼에서 모바일 사용자 전용 아이콘 하나에 위 헤더의 아이콘 링크 TC를 사용하고 있습니다.