WordPress Redirect User after Login
You can use the bellow code in your WordPress Theme to redirect a user after login according to the role assigned to them.Just open your function.php and copy and paste the code into it. Thats all, it will work fine with almost versions of WordPress. If any issues occured plesae inform us using comment box below.
<?php function Redirect_User() { //retrieve current user info global $current_user; get_currentuserinfo(); //If login user role is Subscriber else if ($current_user->user_level == 0) { wp_redirect( home_url() ); exit; } //If login user role is Contributor else if ($current_user->user_level > 1) { wp_redirect( home_url() ); exit; } //If login user role is Editor else if ($current_user->user_level >8) { wp_redirect( home_url() ); exit; } // For other rolse else { $redirect_to = 'http://example.com/'; return $redirect_to; } } add_action('admin_init','Redirect_User'); ?> |