I want to redirect all users except the admin away from the wp-admin page.
If the logged in user tries to access /wp-admin then they will be redirected back home.
Right now they get a page that says "Sorry you are not allowed to access this page"
Can y'all please help me construct a function in my functions.php file to check for these conditions and redirect?
This is what I have, and it isn't working for what I want.
function acme_login_redirect( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
}
add_filter( 'login_redirect', 'acme_login_redirect', 10, 3 );