User Registration

  1. Home
  2. Docs
  3. User Registration
  4. How to?
  5. How to Redirect to a Specific Page after Logout?

How to Redirect to a Specific Page after Logout?

After your users log out from their accounts on your site, you need to redirect them to a certain page. It may be the homepage of your site or, any other page.

To redirect the users after they log out, you need to add a small piece of code to the functions.php file of your active theme.

For this, go to your admin dashboard, and click on Appearances -> Theme Editor. Now, you’ll see the list of files on the right which includes the Theme Functions (functions.php). Click on the functions.php file.

In the functions.php file, simply add the code below:

add_action( 'wp_logout', 'ur_redirect_after_logout');

function ur_redirect_after_logout(){
         wp_redirect( home_url() );
         exit();
}

Adding this code will redirect the users to the homepage. If you want to redirect users to any other page then all you need to do is replace home_url() with the slug of the page you want to redirect.

For example, if you want to redirect to www.example.com/testing then replace home_url() with ‘testing’ and it will do the trick.

Note: Don’t miss the single quote while replacing it with the slug.

Was this article helpful to you? Yes 4 No 7

How can we help?