Advertisement
sabbirshouvo

Show Logged in user to Nav menu

Apr 15th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1.  //Add login/logout link to naviagation menu
  2. function add_login_out_item_to_menu( $items, $args ){
  3.  
  4.     //change theme location with your them location name
  5.     if( is_admin() || $args->theme_location != 'top-menu' )
  6.     return $items;
  7.  
  8.     $redirect = ( is_home() ) ? false : get_permalink();
  9.     if( is_user_logged_in( ) ){
  10.    
  11.         $user=wp_get_current_user();
  12.         $name=$user->display_name; // or user_login , user_firstname, user_lastname
  13.        
  14.         $link = '<a href="' . wp_logout_url( $redirect ) . '" title="' . __( 'Logout' ) .'">' . __( 'প্রস্থান' ) . '</a><a href="' . get_author_posts_url($user->ID) . '>' .$name. '</a>';
  15.     }
  16.     else{
  17.         $link = '<a href="' . wp_login_url( $redirect ) . '" title="' . __( 'Login' ) .'">' . __( 'প্রবেশ' ) . '</a><a href="' . wp_registration_url($redirect) . '" title="' . __( 'Register' ) .'">' . __( 'নিবন্ধন' ) . '</a>';
  18.     }
  19.     return $items.= '<li id="log-in-out-link" class="menu-item menu-type-link">'. $link . '</li>';
  20. }
  21. add_filter( 'wp_nav_menu_items', 'add_login_out_item_to_menu', 50, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement