How to force all logged-out visitors in WordPress

By default, when a user logs out from a WordPress website, he or she will be taken back to the login page with a message notifying the user about successful logout.

But what if you want your users to be automatically redirected to your homepage after logout, I will use the wp_redirect hook following the steps below:

Please ensure that you backup this file before pasting the code.

  1. Login to the WordPress admin panel.
  2. Click Appearance and then click Theme Editor.
  3. Select functions.php on the list of files.
  4. Add an action to the auto_redirect_after_logout hook with the following code:
//Redirect function
function auto_redirect_after_logout(){
   wp_redirect( home_url() );
//Fire action
  1. Save changes.
  2. Logout and test.

This can also be achieved by using the Login and Logout Redirect plugin. The plugin adds an extra option in the Settings page ( Setting > General ), for specifying the redirect URL for login and logout.

Enter desired URLs, save changes and you’re done!

Leave a Reply

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