Users & Login PHP Beginner

Redirect Users After They Log Out

Send people to your home page, or any page you choose, after they log out instead of the "You are now logged out" screen.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 8 lines
add_filter( 'logout_redirect', function ( string $redirect_to, string $requested, $user ): string {
	// Respect a redirect set by a plugin or a logout link with ?redirect_to=.
	if ( '' !== $requested ) {
		return $redirect_to;
	}

	return home_url( '/' );
}, 10, 3 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

After logging out, WordPress shows the login form with a “You are now logged out” message. For customers and members it’s more natural to land back on your site. This snippet redirects them to the home page.

How it works

The logout_redirect filter sets where WordPress sends people after logout. If the logout link already asked for a page with ?redirect_to=, the snippet leaves it alone. Otherwise it returns your home page.

Things to watch

  • Change home_url( '/' ) to any page, for example home_url( '/goodbye/' ).
  • WooCommerce’s My Account logout link already redirects to the My Account page, and this snippet keeps that.

How to test it

Log in, then click Log Out. You should land on your home page.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only