For redirect non admin users to home page and disallow back end access in WordPress, you need to simply copy and paste the following code in your theme’s functions.php file.

function redirect_non_admin_user(){
    if ( !defined( 'DOING_AJAX' ) && !current_user_can('administrator') ){
        wp_redirect( site_url() );  exit;
    } 
}
add_action( 'admin_init', 'redirect_non_admin_user' );

Have any doubt, then comment here!

Leave a Reply

Your email address will not be published. Required fields are marked *