SHARE
TWEET

Untitled

a guest Sep 12th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function add_login_logout_to_menu( $items, $args ) {
  2.     if ( $args->theme_location != 'primary' ) {
  3.         return $items;
  4.     }
  5.  
  6.     if ( !is_user_logged_in() ) {
  7.         $items .= '<li><a href="'.wp_login_url().'" title="Login">Login</a></li>';
  8.     } else {
  9.         $current_user = wp_get_current_user();
  10.         $items .= '<li class="menu-item-has-children"><a href="#">'. $current_user->display_name .'</a><ul class="sub-menu">';
  11.         $items .= '<li><a href="'.wp_logout_url( home_url() ).'">Logout</a></li>';
  12.         $items .= '</ul></li>';
  13.     }
  14.  
  15.     return $items;
  16. }
  17.  
  18. add_filter( 'wp_nav_menu_items', 'add_login_logout_to_menu', 199, 2 );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top