Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1349256

    Hello, I am looking to add code in the “Header Phone Number/Extra Info” area. How can I have a link that shows “login” when not logged in and “logout” when logged in?

    #1349257

    Hey virtualbis,
    Try adding this code to your Header Phone Number/Extra Info area:

    <ul class="account"><li class="login"><a href="/my-account/">[av_font_icon icon='ue824' font='entypo-fontello' size='20px'][/av_font_icon] Login</a></li><li class="logout"><a href="/my-account/customer-logout/">[av_font_icon icon='ue825' font='entypo-fontello' size='20px'][/av_font_icon] Logout</a></li></ul>

    you may need to adjust the url to your specific login and logout urls.
    Then add this code in the General Styling ▸ Quick CSS field or in the WordPress ▸ Customize ▸ Additional CSS field:

    #top .account  {list-style: none;}
    #top .account li { display: inline-block;}
    #top.logged-in .account .login {display: none;}
    #top:not(.logged-in) .account .logout {display: none;}

    After applying the css, please clear your browser cache and check.

    Best regards,
    Mike

    #1349261

    Hi,
    this shows bot login and logout. I would like to only have one at a time. showing “login” when not logged in and “logout” when logged in.

    #1349264

    I just created a shortcode to do this and it is working but the sortcode is not in the same place as the rest of the text. Instead of being to the right it is aligned to the left. I noticed it is outside of <div class=”phone-info “>. How can I include the shortcode in the same div?

    The text in the box is: test [user_logged_in]

    The shortcode is below:

    function user_logged_in_function() {
    if ( is_user_logged_in() ) {
    echo ‘<div class=”phone-info “>Logout</div>’;
    }else{
    echo ‘<div class=”phone-info “>Login</div>’;
    }
    }
    function register_shortcodes(){
    add_shortcode(‘user_logged_in’, ‘user_logged_in_function’);
    }
    add_action( ‘init’, ‘register_shortcodes’);

    #1349290

    Hi,
    Thanks for the feedback, I thought that you had wanted the login & logout to be a link, the solution I provided was a link and only one would show at a time, either the login link or the logout link, if both were showing for you then you had an error in your css or you had not cleared your cache.
    Nonetheless, your shortcode only shows text login & logout but you have tried to create a phone-info div inside a phone-info div, I recommend creating a unique span instead and you don’t need to call the register_shortcodes so your solution is:

    function user_logged_in_function() {
    if ( is_user_logged_in() ) {
    return '<span class="log-info ">Logout</span>';
    }else{
    return '<span class="log-info ">Login</span>';
    }
    }
    add_shortcode('user_logged_in', 'user_logged_in_function');

    Best regards,
    Mike

    #1349306

    Appreciate the explanation. Thanks Mike. Everything is working now.

    #1349357

    Hi,

    Great, I’m glad that Mike could help you out. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.