In general, default WordPress system is built to show dashboard after successful login. But sometimes we need to redirect our users to any other page rather than go into dashboard.
Here i am giving few examples code which you need to place in functions.php file to work.
Example-1: This example redirects admins to the dashboard and other users to the homepage.
function my_login_redirect( $redirect_to, $request, $user ) { //is there a user to check? global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { //check for admins if ( in_array( 'administrator', $user->roles ) ) { // redirect them to the default place return $redirect_to; } else { return home_url(); } } else { return $redirect_to; } } add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Example-2: Below example redirects to homepage for all types of users .
function redirect_home( $redirect_to, $request, $user ) { return home_url(); } add_filter( 'login_redirect', 'redirect_home', 10, 3 );
Example-3: This example also redirects all admins to the dashboard and other users to the homepage.
function my_login_redirect( $redirect_to, $request, $user ) { return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url(); } // end soi_login_redirect add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
If anyone doesn’t like to change functions file code they can use the plugin. Here i am attaching one plugin that can solve the same issue.
This plugin redirect users to specific locations after login, based in the role and is compatible with custom roles and new links in the sidebar of the admin panel and you can also set a custom URL to redirect the user.
This post has already been read 6479 times!
What is Lead Capture: In general sense lead capture designates a process or way of…
Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…
Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…
Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…
Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…
There is an occasional bug for iPhone and iPad even they are designed as well and…