BuddyPress how to show only subscribers on the members page

Going to a BuddyPress members page will show all registered users including the Administrators. We might want to remove/hide the administrator users from the members page.

To only show subscribers in a members page add the following code snippet to the child theme functions file or a code snippet plugin.

// Remove administrator from the member directory page: 
// https://my.seventhqueen.com/docs/seeko/hide-admin-users-from-the-members-directory/

function seeko_hide_admins_from_directory( $qs = false, $object = false ) {
	$excluded_user = implode( ',', get_users( 'role=administrator&fields=ID' ) );
		if ( $object != 'members' && $object != 'friends' ) 
        // hide administrator for members & friends
		return $qs;
		$args = wp_parse_args( $qs );

		if( ! empty( $args['user_id'] ) )
		return $qs;
		if( ! empty( $args['exclude'] ) )
		$args['exclude'] = $args['exclude'] . ',' . $excluded_user;

		$args['exclude'] = $excluded_user;
		$qs = build_query( $args );
		return $qs;

add_action( 'bp_ajax_querystring', 'seeko_hide_admins_from_directory', 20, 2 );
Hide/Remove Administrator users from the BuddyPress Members page.

The above screenshot does not include the Administrator user as the admin has been hidden/removed from the members page after having added the code snippet.


Thanks to https://my.seventhqueen.com/docs/seeko/hide-admin-users-from-the-members-directory/ for providing the code example.

This tutorial was originally written 1 July 2018.


Leave a Reply

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