Add a Logout Link to Your WordPress Menu Without a Plugin

Most WordPress sites welcome visitors with a clear Log In link, but they forget the other half of the journey. A logged in member who wants to sign out has to hunt for the logout option or type a logout URL by hand. That is a security risk on shared computers, because a member who cannot find the logout link may simply close the tab and stay signed in. Adding a logout link to your menu fixes this in a few minutes, and you do not need a plugin to do it.
WordPress already has the tools built in. The Menus screen has a Login/Logout panel that adds a link which changes automatically, showing Log In to guests and Log Out to members. A custom link gives you full control over the destination after logout. A short code filter gives you the most control of all, because it adds the link only when a user is logged in. This guide covers all three methods in order of difficulty.
Why should you add a logout link to your WordPress menu?
A logout link is a basic part of good member experience. When the logout link sits in the main menu, members can leave in one click from any page. That matters most on shared devices in schools, libraries, and offices, where staying signed in can expose private orders and account details to the next person who uses the computer. A visible logout link also builds trust, because members feel in control of their own account.
Method 1: How do I add a logout link with the built-in Login/Logout panel?
Method 1 uses a panel that WordPress hides by default, and it needs no code at all. Open your dashboard, go to Appearance, then Menus, and click the Screen Options tab at the top right corner. Tick the box for Login/Logout, and a new panel appears on the left side with two items inside it, Log In and Log Out. Tick the Log Out checkbox, then click Add to Menu.
WordPress adds a menu item that switches automatically. A guest sees a Log In link in that spot, and a logged in member sees a Log Out link. Drag the item to the position you want, then click Save Menu. Test it in a private browser window: open your site while logged out and confirm the menu shows Log In, then log in and confirm the same spot now shows Log Out. If a plugin or your host caches the menu, clear the cache and test again. For a related login improvement, read our guide to customize the WordPress login page without a plugin.
Method 2: How do I add a logout link with a custom link and a redirect?
Method 2 gives you control over where members land after they log out. The built-in panel sends members to the login page, but you may prefer to send them to your homepage or a thank you page. Go to Appearance, then Menus, and open the Custom Links panel on the left. In the URL field, paste the logout address for your site, replacing yoursite.com with your own domain. Set the Link Text to Log Out, click Add to Menu, and save the menu.
https://yoursite.com/wp-login.php?action=logout&redirect_to=https://yoursite.com/
The redirect_to part tells WordPress where to send the member after the logout is complete. You can change the second address to any page on your site. WordPress asks for confirmation on the logout screen before signing the user out when the link is used this way, which is a safety step that stops other sites from logging your members out with a hidden link. That confirmation page is normal, and members only need one extra click.
The one weakness of Method 2 is that the custom link shows to everyone, including guests who are not logged in. A guest who clicks Log Out sees a confusing screen, because there is no session to end. If your site has many guests and few members, Method 1 or Method 3 is a better fit. If your site is mostly members, a custom link is simple and clear. You can also place the link inside a dropdown, as explained in our guide to add a dropdown menu in WordPress.
Method 3: How do I add a logout link with the wp_nav_menu_items filter?
Method 3 uses a small PHP filter, and it is the most flexible option. The wp_nav_menu_items filter lets you change a menu before WordPress prints it, so you can add a Log Out item only when the visitor is logged in, and only to the menu you name. Add the code below to your child theme functions.php file, or add it as a snippet with the Code Snippets plugin set to run on the front end only. Never edit your parent theme directly, because a theme update will erase your change. For help with child themes, read the official theme guide on developer.wordpress.org.
add_filter( 'wp_nav_menu_items', 'vu_add_logout_link', 10, 2 );
function vu_add_logout_link( $items, $args ) {
if ( is_user_logged_in() && 'primary' === $args->theme_location ) {
$items .= '<li><a href="' . esc_url( wp_logout_url( home_url() ) ) . '">Log Out</a></li>';
}
return $items;
}
Change the word primary to the theme location of your own menu if your theme uses a different name, such as main, header, or top. You can find the location name in the Menus screen, where each menu shows its assigned location, or in your theme documentation. The wp_logout_url function builds the logout address for you and adds the security check that WordPress needs. Change home_url to another page address if you want members to land somewhere else after logging out. Keep a backup of functions.php before you edit it, because a small typo in that file can break your whole site.
How do I show the logout link only to logged-in users?
Showing a logout link to guests is confusing, and hiding it from members defeats its purpose. Method 1 does this automatically, because the built-in item switches between Log In and Log Out. Method 3 does it with the is_user_logged_in check in the code. Method 2 cannot do it on its own, because a custom link has no condition attached to it. If you already use Method 2 and want to hide it from guests, move to Method 3, or put the logout link in an account menu that only members can reach. Our guide to redirect users after login in WordPress pairs well with this setup.
How do I add a logout link in a block theme with the Navigation block?
Block themes, such as Twenty Twenty-Four and Twenty Twenty-Five, do not use the classic Appearance Menus screen. They manage menus with the Navigation block inside the Site Editor. Open Appearance, then Editor, then Navigation, and select the menu you want to edit. Add a Custom Link block, set its URL to your logout address with the redirect you want, and set its label to Log Out. Save the change, and the link appears in your header navigation.
The Navigation block has the same limit as Method 2. A custom link shows to every visitor, so guests see a Log Out link they cannot use. Block themes have no built-in Login/Logout panel in the Site Editor, so you need a small code solution for the automatic switching. The wp_nav_menu_items filter from Method 3 works in block themes too, because it filters the menu output rather than the editor screen.
How do I style the logout link so it looks like a button?
A plain text link can get lost among other menu items, so many sites style the logout link as a small button. Open the Menus screen, click Screen Options, and tick the CSS Classes box. A new field appears on every menu item. Open your Log Out item, type logout-link in the CSS Classes field, and save the menu. Then go to Appearance, then Customize, then Additional CSS, and add a rule that gives that class a dark background, white text, and rounded corners.
.logout-link a{background:#111827;color:#fff!important;padding:8px 16px;border-radius:999px}
Change the background colour to match your brand, and keep the text short so the button fits on small screens. A button style works best when the logout link is the last item in the menu. Test the button on a phone, because a wide button can push the menu into a second line. A fast host also helps the menu and the logout redirect load quickly, and our web hosting guide explains what to look for when you choose one.
How do I test the logout link and fix common problems?
- Open your site in a private window while logged out and confirm the menu shows Log In.
- Log in as a test member, reload, and confirm the menu now shows Log Out.
- Click Log Out and confirm you reach the page you chose as the redirect.
- Check the menu on a phone and confirm the link is visible and easy to tap.
- Clear your caching plugin, CDN cache, and hosting cache if the menu shows the old version.
- Deactivate menu or membership plugins one by one if the link never appears.
The most common problem is a cached menu. Caching plugins and hosts often store one version of a page for guests and another for logged in users, but a misconfigured cache can serve the wrong version to the wrong visitor. Purge the cache after every menu change, and ask your host whether logged in pages are cached. If the link appears in the wrong menu, check the theme location in the Menus screen. If Method 3 shows nothing, confirm the theme location in the code matches your menu location exactly, and confirm the snippet is set to run on the front end. If the site shows a white screen after you edit functions.php, remove the code you just added through your hosting file manager or FTP. WordPress.org has more detail on menus and user functions.
Frequently asked questions
Does WordPress have a built-in logout link for menus?
Yes, in classic themes. Go to Appearance, then Menus, open Screen Options, tick Login/Logout, and add the Log Out item to your menu. It switches automatically, showing Log In to guests and Log Out to members. Block themes do not have this panel, so they need a custom link or the code filter from Method 3.
Can I add a logout link to my WordPress menu without a plugin?
Yes. The built-in Login/Logout panel needs no plugin and no code, a custom link needs only a URL with a redirect, and the wp_nav_menu_items filter needs a few lines of PHP in a child theme. All three methods work without installing anything, and the first two take only a few minutes.
Why does my logout link show to visitors who are not logged in?
You are probably using a custom link, which has no login check attached to it. Custom links show to everyone. Switch to the built-in Login/Logout panel, which hides the logout option from guests, or use the code filter from Method 3, which checks is_user_logged_in before it adds the link.
How do I redirect users to my homepage after logout?
Add redirect_to with your homepage address to the logout URL, as shown in Method 2, or pass home_url into wp_logout_url in the code filter, as shown in Method 3. Test the redirect in a private window while logged in as a test member, and clear your cache if the old destination keeps loading.
Last updated: November 2026.



