How to Make WordPress Redirect After Logout

If you want to make your WordPress site redirect to the home page or any other page you want after logging a user out, there is a simple way to do it. Simply add the following PHP code at the end of your theme’s function.php file and done!

//Ian’s function to redirect after logout:
add_action(‘wp_logout’,’unlog’);
function unlog(){
  wp_redirect(“http://www.petermichaelsonjewellery.com.au/logout-thank-you/”);
  exit();
}//end unlog function by Ian L. of Jafty.com

The above code would cause your site to redirect to the URL inside of the wp_redirect function above, so clearly you need to change that url to fit your needs. You can also use another WordPress function with wp_redirect. For example, say you want to redirect users to the home page after logging out, then you could use this the below line, just replace the above wp_redirect call with this one:

wp_redirect( home_url() );

Summary

As you can see, adding a few simple lines to your theme folder’s function.php file makes it easy to redirect users wherever you want after logging out.

Leave a Reply

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