Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Add login/logout link to menu

Add login/logout link to navigation menus by hooking to `wp_nav_menu_items` filter.

function add_login_logout_menu_link( $items, $args ) {
	
	// Make sure you change 'primary' to the actual theme location of the menu.
	if ( $args->theme_location == 'primary' ) {
	
	    if ( is_user_logged_in() ) {
	        $items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Log Out', 'generatewp' ) . '</a></li>';
	    } else {
	        $items .= '<li><a href="' . wp_login_url( get_permalink() ) . '">' . __( 'Log In', 'generatewp' ) . '</a></li>';
	    }
	
	}
	return $items;
	
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_menu_link', 10, 2 );