Created
April 8, 2014 12:12
-
-
Save hchouhan/10115483 to your computer and use it in GitHub Desktop.
Redirect Users After Login In WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://www.paulund.co.uk/redirect-login-wordpress | |
function redirect_home( $redirect_to, $request, $user ) | |
{ | |
return home_url(); | |
} | |
add_filter( 'login_redirect', 'redirect_home' ); | |
function only_admins_login_area( $redirect_to, $request, $user ) { | |
global $user; | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) | |
{ | |
//check for admins | |
if ( in_array( 'administrator', $user->roles ) ) | |
{ | |
// Redirect to default admin area | |
return $redirect_to; | |
} | |
} | |
return home_url(); | |
} | |
add_filter( 'login_redirect', 'only_admins_login_area', 10, 3 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment