//* Add a Login/Logout toggle item in WordPress navigation menu
add_filter('wp_nav_menu_items', 'customprefix_add_loginout_navitem', 10, 2);
function customprefix_add_loginout_navitem($items, $args) {
    if ($args->theme_location == 'primary') {
        // Replace "primary" with your theme's menu name
        if (!(is_user_logged_in())) {
            $login_item = '<li class="menu-item login-menu-item"><a itemprop="url" href="/wp-login.php" rel="nofollow">Log in</a></li>';
        } else {
            $login_item = '<li class="menu-item logout-menu-item">' . wp_loginout($_SERVER['REQUEST_URI'], false) . '</li>';
        }
        $items.= $login_item;
    }
    return $items;
}