Redirect to Homepage Snippet

//redirect admins to the dashboard and other users to the homepage

function my_login_redirect( $redirect_to, $request, $user ){
//is there a user to check?
if( is_array( $user->roles ) ) {
//check for admins
if( in_array( “administrator”, $user->roles ) ) {
// redirect them to the default place
return home_url( ‘/wp-admin/’ );
} else {
return home_url();
}
}
}
add_filter(“login_redirect”, “my_login_redirect”, 10, 3);

 

Redirect to requested page

If you want to redirect users to the requested page change home_url(); to $request;

Leave a Reply