Redirect Users after Login – WordPress

Paste this code in your functions.php and every time any non-administrator logs in he will be redirected to the home page.

add_filter("login_redirect", "subscriber_login_redirect", 10, 3);

function subscriber_login_redirect($redirect_to, $request, $user){

if(is_array($user->roles)){

if(in_array('administrator', $user->roles)) return home_url('/wp-admin/');

}

return home_url();

}

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*