Rishabh
Rishabh

Reputation: 650

Redirect non admin user on specific page in wordpress

I have edited wordpress login redirect for non admin user to the home page with the help of an article found via google. But in that article it used function to direct to the home page of site not URL. But I want to redirect on a specific page of my project. The code I have used is

function admin_login_redirect( $redirect_to, $request, $user )
{
    global $user;
    if( isset( $user->roles ) && is_array( $user->roles ) ) {
        if( in_array( "administrator", $user->roles ) ) {
            return $redirect_to;
        } else {
            return home_url();
        }
    }
    else
    {
        return $redirect_to;
    }
}
add_filter("login_redirect", "admin_login_redirect", 10, 3);

How do I redirect to a specific page...

Upvotes: 1

Views: 1529

Answers (1)

Shravan Sharma
Shravan Sharma

Reputation: 989

@James Jones demand here is the solution

you can use get_permalink( page_id ) in place of home_url()

Upvotes: 1

Related Questions