Skip to main content
Formatted code
Source Link
Buttered_Toast
  • 2.8k
  • 1
  • 8
  • 21

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.

  return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
}
add_filter( 'login_redirect', 'acme_login_redirect', 10, 3 );
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 );

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.

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

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 );
Source Link

Redirection of users away from wp-admin (but not administrators)

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.

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