1
votes

I used login_redirect hook for redirect to custom url. while i use $redirect_to. It is now working. But while i echo $redirect_to it shows correct url.

I have set the redirect_to parameter in login form also.

 function my_login_redirect( $redirect_to, $request, $user ) {

   echo $redirect_to;

//is there a user to check?
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    //check for admins
    if ( in_array( 'administrator', $user->roles ) ) {
        // redirect them to the default place
        return $redirect_to;
    } else {
        // return home_url();
        return  $redirect_to; 
        die();
    }
} else {
    return $redirect_to;
}

}

add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

1
well i found the solution. i used wp_redirect() inside my_login_redirect() i when the user is not administrator. - Rocky Prajapati

1 Answers

0
votes

well i found the solution. i used wp_redirect() inside my_login_redirect() i when the user is not administrator.