Skip to content

Instantly share code, notes, and snippets.

@stuartduff
Created July 22, 2015 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartduff/e423ea5dbd40f0497b64 to your computer and use it in GitHub Desktop.
Save stuartduff/e423ea5dbd40f0497b64 to your computer and use it in GitHub Desktop.
Adding this snippet to the functions.php of your wordpress theme will redirect visitors to the page they were viewing after logging in.
if ( ( isset( $_GET['action'] ) && $_GET['action'] != 'logout' ) || ( isset( $_POST['login_location'] ) && ! empty( $_POST['login_location'] ) ) ) {
add_filter('login_redirect', 'my_login_redirect', 10, 3);
function my_login_redirect() {
$location = $_SERVER['HTTP_REFERER'];
wp_safe_redirect( $location );
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment