Redirect users/customers away from wp-admin

Use this code in the functions.php file for the active theme. Currently it will redirect users to /my-account – change as you like

add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() . "/my-account" );
exit;
}
}