-
AuthorPosts
-
April 24, 2022 at 12:22 am #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?
April 24, 2022 at 1:36 am #1349257Hey 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,
MikeApril 24, 2022 at 2:06 am #1349261Hi,
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.April 24, 2022 at 3:48 am #1349264I 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’);April 24, 2022 at 7:14 pm #1349290Hi,
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,
MikeApril 25, 2022 at 1:32 am #1349306Appreciate the explanation. Thanks Mike. Everything is working now.
April 25, 2022 at 8:54 am #1349357 -
AuthorPosts
- You must be logged in to reply to this topic.