Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created March 16, 2015 08:31
Show Gist options
  • Save vishalbasnet23/4fec68207a3a9571801b to your computer and use it in GitHub Desktop.
Save vishalbasnet23/4fec68207a3a9571801b to your computer and use it in GitHub Desktop.
Login redirect WP
<?php
function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
global $user;
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();
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment