By: Prem Tiwari | Last Updated: | In: WordPress, WordPress Beginners, WordPress Snippets
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'); ?> |
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari
how to redirect user to a page, redirect user after login, redirect user to a page, wordpress