Redirect Users After Logout in WordPress

By default, WordPress sends a logged out user back to the login page. That is fine for a personal blog, but on a membership site, a store, or a course platform it feels wrong. A customer who just finished shopping does not want to land on wp-login.php, and a member who logs out expects to arrive back at your homepage or a friendly goodbye page. The good news is you can control where users go after logout with one small code snippet, and you do not need a plugin to do it.
This guide shows you how to redirect users after logout in WordPress without a plugin. You will learn the one hook that controls the redirect, where to put the snippet safely, how to send different user roles to different pages, and how to test and troubleshoot the result.
How does the WordPress logout redirect work?
When a user clicks a logout link, WordPress runs the wp_logout action and then redirects to a URL. By default that URL is the login page, because WordPress assumes the user might want to log back in. The logout_url function builds the logout link, and the redirect destination can be changed with the logout_redirect filter.
The filter receives three values: the default redirect URL, the requested redirect URL, and the user object. Your snippet checks the user if needed and returns the URL you want. Because it is a filter, it runs every time a logout link is created, so it works for the admin bar logout link, the logout link in the My Account page, and any logout link your theme shows. You only need one small function.
Where should you put the snippet?
Never edit your theme files directly to add a snippet, because a theme update will wipe it out. Use the Code Snippets plugin or a child theme functions.php file instead. The Code Snippets plugin is the safer choice for most site owners, since you can turn a snippet on and off without touching files and it survives theme changes.
Install Code Snippets from the plugin directory, then go to Snippets and click Add New. Give the snippet a clear name such as Redirect After Logout, paste the code, choose Run snippet everywhere, and save and activate it. If you prefer the child theme route, add the same function to your child theme functions.php file and save.
Whichever route you choose, test the snippet on a staging copy first if your site takes payments or runs a membership plugin. A bad snippet can lock you out of the admin area, so keep a backup and know how to disable the snippet from your hosting file manager if something goes wrong. If you want a deeper look at safe snippet habits, see the WordPress developer handbook on filters and our guide on how to redirect users after login in WordPress without a plugin, which uses the same pattern in the other direction.
The basic snippet: redirect everyone to the homepage
This is the simplest version. Every user who logs out lands on your homepage.
add_filter( 'logout_redirect', function( $redirect_to, $requested_redirect_to, $user ) {
return home_url();
}, 10, 3 );
The function takes the default redirect and replaces it with your homepage URL. The 10 is the priority and the 3 tells WordPress to pass all three arguments. Keep both numbers exactly as written. Save the snippet, activate it, and log out in a private window to see the result.
Redirect to a custom page instead
A custom goodbye page feels more polished than the homepage. Create a page called Goodbye or See You Soon with a short message and a login link, publish it, then point the snippet at it by slug.
add_filter( 'logout_redirect', function( $redirect_to, $requested_redirect_to, $user ) {
return home_url( '/goodbye/' );
}, 10, 3 );
Change /goodbye/ to the slug of your own page. Make sure the page is published and public, because a draft or private page will show a 404 to logged out users. You can also point the redirect at any full URL, such as a landing page on another domain, by returning that URL instead of home_url().
Redirect different user roles to different pages
On a site with several user types, one destination rarely fits everyone. Customers can go to the shop, subscribers to a thank you page, and administrators to the homepage. Check the user object before you return a URL.
add_filter( 'logout_redirect', function( $redirect_to, $requested_redirect_to, $user ) {
if ( ! $user || is_wp_error( $user ) ) {
return home_url();
}
if ( in_array( 'customer', (array) $user->roles, true ) ) {
return home_url( '/shop/' );
}
if ( in_array( 'subscriber', (array) $user->roles, true ) ) {
return home_url( '/goodbye/' );
}
return home_url();
}, 10, 3 );
The first check guards against a missing or broken user object. Then each role gets its own destination, and anyone else falls back to the homepage. Add more role checks in the same pattern if your site has extra roles from a membership or eCommerce plugin. Just make sure the role names match exactly what your site uses, because WordPress role slugs are case sensitive.
How to test the logout redirect
Test with a real user account, not only as an administrator. Create a test subscriber account, log in with it in a private window, then click the logout link from the admin bar or the My Account page. You should land on the URL your snippet returns. Repeat the test for each role you redirect differently.
Also test the links your theme and plugins generate. Some themes build their own logout link with a hardcoded redirect, and a membership plugin may override the default logout flow. If your snippet works from the admin bar but not from a plugin page, the plugin is the likely cause, and its own settings or documentation will tell you how to change its redirect.
Clear your cache before you conclude that the snippet failed. A cached page can show the old behaviour for a while, especially if your host or caching plugin caches the logout URL. Clear the cache, close the private window, and test again in a fresh one.
Common problems and quick fixes
The most common problem is the redirect simply not happening, and the user still lands on the login page. Check first that the snippet is active in Code Snippets or present in the child theme file. Then confirm the filter name is logout_redirect and not login_redirect, because the two are easy to confuse.
A redirect loop is the second common issue. It happens when your destination page itself requires a login, so WordPress sends the logged out user back to the login page, which then redirects again. Make sure the goodbye page is public and does not sit behind a membership rule.
A white screen after saving the snippet means a syntax error. Deactivate the snippet from the Code Snippets list or remove it from functions.php through your hosting file manager, then check the code for a missing bracket or semicolon. Paste the snippet exactly as written in this guide and do not retype the quotes by hand, because smart quotes break PHP.
For official background on the hooks used here, see the WordPress developer reference for logout_redirect and wp_logout_url. If your site is a WooCommerce store, the same snippet works there too, and it pairs well with our guide on how to disable guest checkout in WooCommerce. And if your users log in through a custom page, keep the whole flow consistent by reviewing your web hosting setup so login and logout pages load fast and reliably.
Frequently asked questions
Can I redirect users after logout in WordPress without a plugin?
Yes. Add a small function that hooks into the logout_redirect filter, using the Code Snippets plugin or your child theme functions.php file. The snippet returns the URL you want, such as your homepage or a custom goodbye page, and WordPress sends every logged out user there.
Why does WordPress send users to the login page after logout?
That is the built in default. WordPress assumes a logged out user may want to log back in, so the logout flow ends at wp-login.php unless a snippet or plugin changes the destination through the logout_redirect filter.
Can I redirect different user roles to different pages?
Yes. Check the user roles inside your filter function and return a different URL for each role. Customers can go to the shop, subscribers to a goodbye page, and everyone else to the homepage. Make sure the role slugs match your site exactly.
Will this snippet work with WooCommerce and membership plugins?
It works with WooCommerce out of the box, because WooCommerce uses the same WordPress logout flow. Some membership plugins replace the logout link with their own, so if the redirect works from the admin bar but not from a plugin page, check that plugin settings for its own redirect option.
Last updated: November 2026.



