Skip to content

How To Auto Redirect Users After Login In WordPress

I have already posted an article about auto redirecting users after they logout out of your WordPress website. In this post, I’ll show you how to redirect users after login in WordPress with a cool trick. We will redirect users to home page and admins to admin panel of your site.

Tom McFarlin coded a great snippet to redirect all the users of your WordPress website to the home page of your site following a successful login attempt & the admins will be redirected to the admin panel of the website.

Just add following snippet to your current theme’s functions.php file:

function soi_login_redirect($redirect_to, $request, $user)
{
    return (is_array($user->roles) && in_array('administrator', $user->roles)) ? admin_url() : site_url();
} 
add_filter('login_redirect', 'soi_login_redirect', 10, 3);

You can also redirect the user to a specific page of your site with this snippet:

function login_redirect( $redirect_to, $request, $user ){
    return home_url('custom-page');
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );

5 thoughts on “How To Auto Redirect Users After Login In WordPress”

    1. add_action(‘wp_logout’,’go_home’);
      function go_home(){
      $location = $_SERVER[‘HTTP_REFERER’];
      wp_safe_redirect($location);
      exit();
      }

Leave a Reply

Your email address will not be published. Required fields are marked *