Want to redirect your users on your website’s specific page after login in your website. If your answer is yes, then this article will help you. In today’s post i will share simple code to redirect your users/visitor after login.
Add below code in functions.php page in current theme.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php function redirect_user_on_role() { //retrieve current user info global $current_user; get_currentuserinfo(); //If login user role is Subscriber 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://google.com/'; return $redirect_to; } } add_action('admin_init','redirect_user_on_role'); ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: how to redirect user to a page, redirect user after login, redirect user to a page, wordpress