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 that 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. Save changes
  4. 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:

add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
wp_redirect( 'http://www.firstsiteguide.com');
exit();
}

source of post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!
%d bloggers like this: