firoze

Automatically add login or logout and Register in Menu

Jul 23rd, 2015
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // Automatically Add login or logout Option Item in Menu
  2.  
  3. add_filter( 'wp_nav_menu_items', 'add_logout_link', 10, 2);
  4. /**
  5. * Add a login link to the members navigation
  6. */
  7. function add_logout_link( $items, $args )
  8. {
  9. if($args->theme_location == 'bishop_menu')
  10. {
  11. if(is_user_logged_in())
  12. {
  13. $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
  14. } else {
  15. $items .= '<li><a href="'. wp_login_url() .'">Log In</a></li>';
  16.  
  17. }
  18.  
  19. }
  20. return $items;
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27. /**
  28. * Add a login link to the members navigation
  29. */
  30. function register( $items, $args )
  31. {
  32. if($args->theme_location == 'bishop_menu')
  33.  
  34. $items .= '<li><a href="'.get_bloginfo('url').'/wp-login.php?action=register">REGISTER</a></li>';
  35.  
  36.  
  37. return $items;
  38. }
  39.  
  40. add_filter( 'wp_nav_menu_items', 'register', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment