How To Auto Redirect Users After Logout In WordPress

By Default, when you hit the logout button in a WordPress website it redirects you to the login page. However you can easily change this behavior and redirect the user to your desired URL by adding a small amount of code to your functions.php file.

To change the logout URL in WordPress use the following code snippet,

//Redirect after logout
add_action('wp_logout','ccw_redirect_logout_url');
function ccw_redirect_logout_url(){
     wp_redirect(home_url())
     exit;
}

The above code will redirect the user to Home page after logout, but you can also redirect the user to a custom URL by replacing ‘home_url’ with your desired link. For example, following code will redirect the user to http://coffeecupweb.com.

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

See Also:

Change default search string “?s=” to permalink structure?

 

 

0 Comments

Leave a Comment.