Skip to main content
Dec 26, 2016

Working with Wordpress, you might want to redirect users after they login to some specific location. Here is function that could help you to achieve this behaviour.

/**
* Function perform user redirection after login based on role
*
*/
function redirect_after_login() {
  // Get current user info 
  global $current_user;
  get_currentuserinfo();
   
  // Subscriber role
  if ($current_user->user_level == 0) {
    wp_redirect( home_url() );
    exit;
  }
  // Contributor role
  else if ($current_user->user_level > 1) {
    wp_redirect( home_url() );
    exit;
  }
  // Editor role
  else if ($current_user->user_level >8) {
    wp_redirect( home_url() );
    exit;
  }
  // For any other roles
  else {
    $redirect_to = 'http://anysite.com/';
    return $redirect_to;
  }
}
add_action('admin_init','redirect_after_login');