stuartduff
7/22/2015 - 8:26 PM

Adding this snippet to the functions.php of your wordpress theme will redirect visitors to the page they were viewing after logging in.

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();
	}
}