// Blocks access to /wp-admin/ for any user without the identified capability (edit_options=administrator)
add_action( 'init', 'my_block_admin_init' );
function my_block_admin_init() {
if ( is_admin() && ! current_user_can( 'edit_options' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
Block access to wp-admin
This post brought to you by RocketGeek, ButlerBlog, and the following: