# Hide Administrators From Other Users

> Removes administrator accounts from the Users screen for anyone who is not an administrator, for example shop managers on a WooCommerce site.

- Type: PHP
- Runs: Admin only
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, roles, privacy
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/hide-administrators-from-user-list/

## Code

```php
add_action( 'pre_get_users', function ( $query ) {
    if ( current_user_can( 'manage_options' ) ) {
        return;
    }

    $excluded   = (array) $query->get( 'role__not_in' );
    $excluded[] = 'administrator';

    $query->set( 'role__not_in', array_unique( $excluded ) );
} );
```

## Notes

The role counts above the list are not changed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Administrators From Other Users" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
