I am a newbie to Wordpress. I am currently working on registration and login. I have a page restrict url let http://xyz.com/abc
. Login/registration is required for this url.
I need that when a user register or login then it should be redirected on this previous url.
In login I have added the following hook :
add_filter('login_redirect', 'redirect_previous_page', 10);
function redirect_previous_page(){
global $user;
$request = $_SERVER["HTTP_REFERER"];
if ( in_array( $user->roles[0], array( 'administrator') ) ) {
return admin_url();
return $redirect_to;
} elseif ( in_array( $user->roles[0], array( 'subscriber') ) ) {
return $request;
return $redirect_to;
}
}
It is working for me, but I am not getting how can I redirect on this url after successful registration. I have registration link on the login page
return
one after the other. Your functions ends on the firstreturn
it meets. You also need arguments in your function. Read the codex for an example.