How to redirect a WordPress user after logout

By default, when a user logs out from a WordPress website, he or she will be taken back to the login page. A message will be shown that notifies a user about successful logout and the rest of navigation is left to users.

But what if you want your users to be automatically redirected to your homepage, discussion pages that you want them to see or any other pages of interest? Maybe you want to create a different logout page which will contain special widgets or lead your users somewhere else? If so, you will need this little code to make everything happen.

In the next few lines, we’re about to show you how to easily redirect a user to any URL you want. If you don’t want to use the code for redirections, we’re about to show you a simple plugin which will do all the for you. But before that, let’s redirect a user to the homepage:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. add_action('wp_logout','auto_redirect_after_logout');
    function auto_redirect_after_logout(){
    wp_redirect( home_url() );
  4. Save changes
  5. Logout and enjoy your beautiful homepage

It is simple as that. As you can guess from the code, you can redirect a user to any other URL by changing the third line. So, if you want to lead your users to another page of your own site or to any external page, your code should look something like this:

function auto_redirect_after_logout(){
wp_redirect( '');

If you want to do more with wp_redirect function, you can learn more about it on WordPress Codex pages.

Login and Logout Redirect


Login and Logout Redirects
This free plugin is relatively simple and will do its job perfectly. Instead of dealing with the code, this plugin will create an additional segment in the settings page. After you install and activate it, you have to navigate to Settings -> General and scroll all the way to the end of the page. Here you will find separate input boxes for Login and Logout redirects. Enter desired URLs, save changes and you’re done!

If you need more redirecting options for your WordPress website, we suggest that you check 5sec Redirect plugin which can help you to redirect any post, page, category, tag or custom URL. It will allow you to cloak your URLs which can be a great thing for hiding affiliate links or if you want to hide any URL from your visitor. The plugin also shows you statistics about each redirected link so that you know what’s happening on the site.

Start Blog Book


This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

2 thoughts on “How to redirect a WordPress user after logout

Leave a Reply

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