Skip to content

WordPress Logout Redirect: Send Users to Any Page

Updated October 2026 by Marius: rewritten for current WordPress and tested on WordPress 7.1. Originally published by Hardeep Asrani in 2014.

By default, WordPress sends users who log out to the login screen (wp-login.php?loggedout=true). On a membership site, a shop or a client site you usually want them somewhere more useful, like the homepage.

The clean way to do that is the logout_redirect filter. WordPress runs it inside wp-login.php just before it redirects, passes it the user who just logged out, and handles the redirect itself, so your code does not need to call exit.

Redirect to the homepage after logout

add_filter( 'logout_redirect', function ( $redirect_to, $requested_redirect_to, $user ) {
	return home_url( '/' );
}, 10, 3 );Code language: PHP (php)

To send users to a specific page instead, change the URL, for example home_url( '/goodbye/' ).

Redirect by user role

Because the filter receives the user, you can send different roles to different places. This version sends WooCommerce customers to the shop and everyone else to the homepage. It also leaves alone any logout link that already asked for a specific destination with redirect_to, so plugins that set their own logout target keep working.

add_filter( 'logout_redirect', function ( $redirect_to, $requested_redirect_to, $user ) {
	if ( $requested_redirect_to ) {
		return $redirect_to;
	}
	if ( $user instanceof WP_User && in_array( 'customer', (array) $user->roles, true ) ) {
		return home_url( '/shop/' );
	}
	return home_url( '/' );
}, 10, 3 );Code language: PHP (php)

Redirect to an external URL

WordPress sends the logout redirect through wp_safe_redirect(), which only allows your own domain. If you return a URL on another domain, WordPress quietly ignores it and falls back to the admin URL. Add the other host to the allowed list first:

add_filter( 'allowed_redirect_hosts', function ( $hosts ) {
	$hosts[] = 'example.com';
	return $hosts;
} );

add_filter( 'logout_redirect', function ( $redirect_to, $requested_redirect_to, $user ) {
	return 'https://example.com/';
}, 10, 3 );Code language: PHP (php)

The host has to match exactly, so www.example.com needs its own entry.

If you only want one link to behave differently, for example a “Log out” link in your theme’s header, pass the destination to wp_logout_url(). It adds the redirect_to parameter and the security nonce for you:

<a href="<?php echo esc_url( wp_logout_url( home_url( '/' ) ) ); ?>">Log out</a>Code language: HTML, XML (xml)

Why not hook into wp_logout?

Older tutorials, including the first version of this one, hook into the wp_logout action, redirect and call exit(). It works, but stopping the script inside wp_logout means any other plugin hooked to the same action at a later priority never runs, which can skip session cleanup or logging. The logout_redirect filter avoids that, and it has been in WordPress since version 4.2.

Where to add this code

Add the snippet with a code snippets plugin instead of your theme’s functions.php, so it survives theme updates and you can switch it off without FTP. This guide shows how with the free Code Snippets plugin. On my own sites I use WPCodeBox, which keeps snippets in a cloud library so the same snippet can go on several sites. (Marius)

Disclosure: the WPCodeBox link is an affiliate link. If you buy through it, I earn a commission at no extra cost to you.

6 thoughts on “WordPress Logout Redirect: Send Users to Any Page”

  1. Thanks for the code. How can you remove or hide pre logout message: You are attempting to log out of websitename

    Do you really want to

    Thanks

    1. Yes but this article is not about changing the logout url, which is automatically generated by WordPress, but to redirect users to certain page after they logged out

  2. Just a couple of things :
    – If you redirect to your own homepage please use “wp_safe_redirect()” instead.
    – Exit statement does not require ()

Leave a Reply

Your email address will not be published. Required fields are marked *