Adding items to a menu

//***********************************************************
//***********************************************************
//********** ADD LOG IN / LOG OUT TO THE MAIN MENU **********
//***********************************************************
//***********************************************************
add_filter( 'wp_nav_menu_items', 'wp_nav_menu_items_loginout_menu_link', 10, 2 );
function wp_nav_menu_items_loginout_menu_link( $items, $args )
{
  //print_r($args);
  if ($args->menu->name == 'Menu-Header')     //<<<The name you have used for the menu
  {
    if (is_user_logged_in())
        $items .= '<li><a href="/log-out">'. __("Log Out") .'</a></li>';     //<<<Log out URL (you can use wp_logout_url() or your own link
    else
        $items .= '<li><a href="'. wp_login_url(get_permalink()) .'">'. __("Log In") .'</a></li>';    //<<<Log out URL (you can use wp_login_url(get_permalink()) or your own link
  }
  return $items;
}

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *