Search code examples
phphtmlcsswordpressmembership

Remove buttons if a user is logged in on WordPress


I have these two buttons in the header:

<a href="/" class="button primary-button">Members</a>
<a href="#/register/" class="button secondary-button">Register Now!</a>

If the user is not logged in or registered, these two buttons should be shown. If logged in, these two should not be shown. How can I do that?


Solution

  • You can check with is_user_logged_in() for if user is logged in wp or not

    if ( is_user_logged_in() ) {
    // your code for logged in user 
    } else {
    // your code for logged out user 
    }
    

    Add Members and Register button for logged out user you need to used below code

    if ( !is_user_logged_in() ) {
      <a href="/" class="button primary-button">Members</a>
      <a href="#/register/" class="button secondary-button">Register Now!</a>
    }