Sometimes you want to add a log in/out link (depending on whether the current user is logged in or not) in your main menu. Here’s a simple way to add them to the end.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in()) { $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>'; } else { $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>'; } return $items; }