Advertisement
xefned

Userpro, userlink in menu, functions.php

Jun 4th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. /* Add Login / Logout to your WordPress Menu */
  2.  
  3. function userpro_add_loginout_navitem($items, $args ) {
  4. $theme_location = 'top-navigation'; //Change "main_menu" to your own theme's main menu location
  5. $current_user = wp_get_current_user();
  6. if( $args->theme_location == $theme_location ) {
  7. if ( !(is_user_logged_in()) ) {
  8. $login_item = '<li class="nav-login menu-item"><a href="/profile/#" class="popup-login">Log In</a></li>'; //login display
  9. $login_item .= '<li class="nav-login menu-item"><a href="/profile/register">Register</a></li>'; //login display
  10. }
  11. else {
  12. $login_item = '<nav>';
  13. $login_item .= '<ul>';
  14. $items .= '<li><a href="#">'.$current_user->user_firstname.' '.$current_user->user_lastname.'</a>';
  15. $items .= '<ul>';
  16. $items .= '<li><a href="/profile/">My Profile</a></li>';
  17. $items .= '<li><a href="/my-projects/">My Projects</a></li>';
  18. $items .= '<li class="nav-login menu-item">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
  19. $items .= '</ul>';
  20. $items .= '</li>';
  21. $items .= '</ul>';
  22. }
  23. $items .= $login_item;
  24. }
  25. return $items;
  26. }
  27. add_filter('wp_nav_menu_items', 'userpro_add_loginout_navitem', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement