Redirect After Login

Redirect users to a specific page after they log in.

<?php
function custom_login_redirect($redirect_to, $requested_redirect_to, $user) {
    // Is there a user to check?
    if (isset($user->roles) && is_array($user->roles)) {
        // check for admins
        if (in_array('administrator', $user->roles)) {
            //Redirect them to the default place
            return home_url('/admin-dashboard');
        } else {
            return home_url();
        }
    } else {
        return $redirect_to;
    }
}
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

Post Comment