UserPro Forums
  • Create new topic
  • Forums
    • No replies topics
    • Newest topics
    • Forum statistics
  • Account
    • Lost password
    • Register
    • Login
  • Documentation
  • Back to main site

Community Forums

User To User Support Forum/Forums/Support Questions (UserPro)/Display Logout Link After Login

Display Logout Link After Login

Logout shortcode
  • 8 years, 11 months ago AvatarPaulVictor1987
    Participant

    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!)?

    8 years, 11 months ago AvatarNexnivis
    Participant

    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 | Register

    If you are logged in you’ll see :
    Welcome, PaulVictor1987! | Logout

    Hope it could help 🙂 And sorry for my english

    8 years, 11 months ago AvatarNexnivis
    Participant

    [username] can be [display_name], [first_name], [last_name], as you want to display

    8 years, 11 months ago AvatarPaulVictor1987
    Participant

    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!

    8 years, 7 months ago AvatarLaure Pamart
    Participant

    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

    8 years, 7 months ago AvatarAnonymous
    Inactive

    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.

    Nav Menu Roles

    8 years, 7 months ago Avatarjmtechglobal
    Participant

    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/

    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    /*
    Add Login / Logout to your WordPress Menu
    */
    function userpro_add_loginout_navitem($items, $args ) {
    $theme_location = &#039;avia&#039;; //Change &quot;avia&quot; to your theme&#039;s main menu location
    $current_user = wp_get_current_user();
    if( $args-&gt;theme_location == $theme_location ) {
    if ( !(is_user_logged_in()) ) {
    $login_item = &#039;&lt;li class=&quot;nav-login menu-item&quot;&gt;&lt;a href=&quot;/profile/#&quot; class=&quot;popup-login&quot;&gt;Log In&lt;/a&gt;&lt;/li&gt;&#039;; //login display
    $login_item .= &#039;&lt;li class=&quot;nav-login menu-item&quot;&gt;&lt;a href=&quot;/profile/register&quot;&gt;Register&lt;/a&gt;&lt;/li&gt;&#039;; //login display
    }
    else {
    //$login_item = &#039;&lt;li class=&quot;nav-login menu-item&quot;&gt;&#039;.wp_loginout($_SERVER[&#039;REQUEST_URI&#039;], false).&#039;&lt;/li&gt;&#039;; //logout display
    //$login_item = &#039;&lt;li class=&quot;nav-login menu-item&quot;&gt;&#039;.echo $current_user.&#039;&lt;/li&gt;&#039;; //logout display
    $login_item = &#039;&lt;nav&gt;&#039;;
    $login_item .= &#039;&lt;ul&gt;&#039;;
    $items .= &#039;&lt;li&gt;&lt;a href=&quot;#&quot;&gt;&#039;.$current_user-&gt;user_firstname.&#039; &#039;.$current_user-&gt;user_lastname.&#039;&lt;/a&gt;&#039;;
    $items .= &#039;&lt;ul&gt;&#039;;
    $items .= &#039;&lt;li&gt;&lt;a href=&quot;/profile/&quot;&gt;My Profile&lt;/a&gt;&lt;/li&gt;&#039;;
    $items .= &#039;&lt;li&gt;&lt;a href=&quot;/my-projects/&quot;&gt;My Projects&lt;/a&gt;&lt;/li&gt;&#039;;
    $items .= &#039;&lt;li&gt;&lt;a href=&quot;/create-project/&quot;&gt;Create Project&lt;/a&gt;&lt;/li&gt;&#039;;
    $items .= &#039;&lt;li class=&quot;nav-login menu-item&quot;&gt;&#039;.wp_loginout($_SERVER[&#039;REQUEST_URI&#039;], false).&#039;&lt;/li&gt;&#039;;
    $items .= &#039;&lt;/ul&gt;&#039;;
    $items .= &#039;&lt;/li&gt;&#039;;
    $items .= &#039;&lt;/ul&gt;&#039;;
     
    }
    $items .= $login_item;
    }
    return $items;
    }
     
    add_filter(&#039;wp_nav_menu_items&#039;, &#039;userpro_add_loginout_navitem&#039;, 10, 2);
     
    8 years, 7 months ago Avataradmin
    Keymaster

    Thanks for sharing this useful code!

    8 years, 4 months ago Avatarumberto86
    Participant

    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!

    8 years, 4 months ago Avatartest
    Participant

    @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”

    8 years, 4 months ago Avatarumberto86
    Participant

    Hi test,
    Just did. Purchase code is now inserted in my profile.

    8 years, 4 months ago Avatarjmtechglobal
    Participant

    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.

    8 years, 4 months ago Avatarumberto86
    Participant

    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,

    8 years, 4 months ago Avatarjmtechglobal
    Participant

    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 🙂

    8 years, 4 months ago Avatarumberto86
    Participant

    Hi jmtechglobal,
    Sorry but to locate my main menu… what am i looking for a php file within my theme folder?

Viewing 15 posts - 1 through 15 (of 21 total)
1 2 →

You must be logged in to reply to this topic.

Disclaimer

This forum is 100% free and USER to USER support only. Technical support staff doesn’t monitor this forum actively.

If you are a customer and want to get technical support from our staff please submit a technical support ticket here: UserPRO Technical Support

Recent Topics

  • Custom Badges AddOn Plugin here
  • Green Trust Cash APplication
  • How to use cash app without a bank account
  • Install Cash App on your Device [100%] by yourself | Step-by-Step Guide
  • Green Trust Cash Application

About forum

Here you can find help from UserPro plugin developers and other UserPro fellow users. Please be polite and ask your questions. NO SPAM!

Search Forums

Follow us

  • facebook
  • twitter
  • youtube
© Copyright UserPro