-
Hi,
Not sure in which forum I should have put this but I’m wondering how I can display a logout link after the user is logged in. I currently have two menu items in the header of my theme (Log in | Register) with the modal popup classes enabled but how can I display a log out link after the user is logged in? Can the Login link be automatically changed to a logout link after page refresh?
Is it also possible to display some kind of welcome message (Welcome Username!)?
If your menu support shortcodes (like UberMenu), you can use [userpro_loggedin] and [userpro_loggedout].
For example :
[userpro_loggedout]Login | Register[/userpro_loggedout][userpro_loggedin]Welcome, [username]! | Logout[/userpro_loggedin]
If you are logged out you’ll see :
Log in | RegisterIf you are logged in you’ll see :
Welcome, PaulVictor1987! | LogoutHope it could help 🙂 And sorry for my english
[username] can be [display_name], [first_name], [last_name], as you want to display
Thanks so much for your help! I have tried using the shortcodes and they work but they are only displayed as text and not links so a user can’t click on the Logout link as that is displayed as text.
Any help is appreciated!
Hello,
I’ve the same question.
I’ve used the code and I’ve had link myself (I’ve replaced my website url by “URL” below) :<?php echo do_shortcode(‘[userpro_loggedout]Login | Register[/userpro_loggedout][userpro_loggedin]Welcome, [first_name] [last_name] ! | Logout[/userpro_loggedin]’); ?>
It seems to work but maybe there is a best wirting ?
Thanks
This is the easiest way to have login and register link in menu for logged out member and a logout link for logged in users.
I wrote a function to do this. Its a little more complex then what’s above but I have also included drop down navigation under the users name that is displayed. Log out and My Profile are some of the sub nav links. Code doesn’t display correctly so don’t copy and past this haha. This also uses the log in pop up. Here is the jfiddle link if you are interested in using it. http://jsfiddle.net/HZscB/
PHP12345678910111213141516171819202122232425262728293031323334353637383940/*Add Login / Logout to your WordPress Menu*/function userpro_add_loginout_navitem($items, $args ) {$theme_location = 'avia'; //Change "avia" to your theme's main menu location$current_user = wp_get_current_user();if( $args->theme_location == $theme_location ) {if ( !(is_user_logged_in()) ) {$login_item = '<li class="nav-login menu-item"><a href="/profile/#" class="popup-login">Log In</a></li>'; //login display$login_item .= '<li class="nav-login menu-item"><a href="/profile/register">Register</a></li>'; //login display}else {//$login_item = '<li class="nav-login menu-item">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>'; //logout display//$login_item = '<li class="nav-login menu-item">'.echo $current_user.'</li>'; //logout display$login_item = '<nav>';$login_item .= '<ul>';$items .= '<li><a href="#">'.$current_user->user_firstname.' '.$current_user->user_lastname.'</a>';$items .= '<ul>';$items .= '<li><a href="/profile/">My Profile</a></li>';$items .= '<li><a href="/my-projects/">My Projects</a></li>';$items .= '<li><a href="/create-project/">Create Project</a></li>';$items .= '<li class="nav-login menu-item">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';$items .= '</ul>';$items .= '</li>';$items .= '</ul>';}$items .= $login_item;}return $items;}add_filter('wp_nav_menu_items', 'userpro_add_loginout_navitem', 10, 2);Hi Jmtechglobal,
I want to apply your code on my wordpress website. I need to insert it on the header.php template and i’m just a newbie at this could you please help me out and let me know when it needs to be applied?Thanks so much!
@umberto86 ,
Can you please verify your purchase as mentioned in the Support Forum Instructions please ? Thank you.
How To:
1. open http://userproplugin.com/userpro/profile/edit/
2. copy & paste your purchase code into the “Envato Purchase Code” field
3. click on “Save Changes”Hi test,
Just did. Purchase code is now inserted in my profile.umberto86 you will want to place that code into your functions.php and change the main menu location to your themes main menu location. Then change the link url’s of course and you should be good to go. I have greatly expanded this function since I last posted it. I have added functionality to it to work with the private messaging add on so that when you click the drop down menu it will show a “Messages” link and if you have new messages it will show that number in parenthesis like this.. Messages (1) etc.. if there is no new messages then it simply just says Messages. Let me know if you are interested in that too.
Hi jmtechglobal,
That would be fantastic, i also bought the messaging plugin, so it would be great if people that login can see their messages.Where exactly do i paste it in the functions.php?
Also how do i change the main menu location? Sorry im really new at this… i appreciate all your help.
Thanks,There is comments in the code that says where to put the menu location. You will need to locate where your main menu location is in your particular theme. Get this all working and then we can expand it to include more features 🙂
Hi jmtechglobal,
Sorry but to locate my main menu… what am i looking for a php file within my theme folder?
You must be logged in to reply to this topic.