How To Add a Login/Logout URL to a WordPress Menu

Quick Summary
- Install the free Login or Logout Menu Item plugin to add a menu link that logs visitors in or logs users out.
- Add its item under Appearance > Menus, enabling it in Screen Options if hidden, then test the menu logged out and logged in.
- A custom link to wp-login.php can't turn into a logout link, and a hand-made logout link lacks the nonce, showing a confirmation screen.
WordPress menus have no built-in item that changes with the visitor’s login state. The simplest way to add one is the free Login or Logout Menu Item plugin from WordPress.org. It adds a menu link that lets logged-out visitors log in and logged-in users log out.
Set it up
- Go to Plugins > Add Plugin, search for Login or Logout Menu Item, then install and activate it.
- Open Appearance > Menus and select the menu you want to edit.
- Find the plugin’s login/logout item in the panels on the left and add it to the menu. If you don’t see it, open Screen Options at the top of the page and enable it.
- Save the menu and test it both logged out (for example in a private window) and logged in.
These steps use the classic Appearance > Menus screen. Check the plugin’s page for its current settings and compatibility before you install it.
Why not a plain custom link
You could add a Custom Link that points to wp-login.php, but it can’t turn into a logout link when the user is signed in. A hand-made logout link also lacks the security nonce WordPress expects, so users land on a confirmation screen instead of being logged out. WooCommerce shows a similar message on its own logout link; see logging WooCommerce customers out without the confirmation. The plugin takes care of both.
If you prefer code over a plugin, the same result is possible with the wp_nav_menu_items filter together with is_user_logged_in(), wp_login_url() and wp_logout_url().
Related articles
- adding image icons to menu items: another menu feature handled by a free plugin
- a dropdown arrow for menu items with submenus: a code-based menu tweak with wp_nav_menu_objects

