# BuddyPress: Hide Administrators From the Members Directory

> Keeps site administrators (and any other roles you list) out of the BuddyPress members directory and member counts on the directory page.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: buddypress, members, directory
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/buddypress-hide-admins-from-directory/

## Code

```php
if ( ! function_exists( 'buddypress' ) ) {
    return;
}

// Roles to hide from the directory.
$wpide_bp_hidden_roles = array( 'administrator' );

add_filter( 'bp_after_has_members_parse_args', function ( $args ) use ( $wpide_bp_hidden_roles ) {
    if ( ! bp_is_members_directory() && ! wp_doing_ajax() ) {
        return $args;
    }

    $hidden = get_transient( 'wpide_bp_hidden_members' );

    if ( false === $hidden ) {
        $hidden = get_users( array( 'role__in' => $wpide_bp_hidden_roles, 'fields' => 'ID', 'number' => 500 ) );
        set_transient( 'wpide_bp_hidden_members', $hidden, HOUR_IN_SECONDS );
    }

    if ( $hidden ) {
        $exclude         = empty( $args['exclude'] ) ? array() : wp_parse_id_list( $args['exclude'] );
        $args['exclude'] = array_unique( array_merge( $exclude, array_map( 'intval', $hidden ) ) );
    }

    return $args;
} );

add_action( 'set_user_role', function () {
    delete_transient( 'wpide_bp_hidden_members' );
} );
```

## Notes

Hidden members can still be found by visiting their profile URL directly. The list of IDs is cached for an hour.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "BuddyPress: Hide Administrators From the Members Directory" 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/
