How to redirect users to same page where user before login in WordPress

Hello friends,

When we create any login or registration page then sometimes we need the functionality to redirect the users to the same page where they are before login.

So today I am going to show you How to redirect users to same page where users before login in WordPress. For this, we need to create this simple function and add it to WordPress’s functions.php file. You can find the functions.php file in your active theme folder.

if( !function_exists('mtz_user_login_redirect') ) {

	function mtz_user_login_redirect() {
	if ( isset( $_REQUEST['redirect_to'] ) ) {
        $redirect_to = $_REQUEST['redirect_to'];
	return $redirect_to;



That’s it. Just copy this function and paste it in the functions.php file.