Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hchouhan/10115483 to your computer and use it in GitHub Desktop.
Save hchouhan/10115483 to your computer and use it in GitHub Desktop.
Redirect Users After Login In WordPress
<?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