/ Published in: PHP
Add Login / Logout to your WordPress Menu. You must have UserPro
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** ******** ******** ******** ******** ******** ******** ******** ******** * TITLE: UserPro: Conditional Log-in / Log-out * DESCRIPTION: Add Login / Logout to your WordPress Menu. You must have UserPro * * http://userproplugin.com/userpro/forums/topic/display-logout-link-after-login/ * http://jsfiddle.net/HZscB/ * */ function userpro_add_loginout_navitem($items, $args ) { //Change "avia" to your theme's main menu location $theme_location = 'yoo_avenue_wp'; $current_user = wp_get_current_user(); if( $args->theme_location == $theme_location ) { if ( !(is_user_logged_in()) ) { //login display $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>'; } else { //logout display //$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>'; $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 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);
URL: http://jsfiddle.net/HZscB/