Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Add Login / Logout to your WordPress Menu */
- function userpro_add_loginout_navitem($items, $args ) {
- $theme_location = 'top-navigation'; //Change "main_menu" to your own 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 = '<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 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement