# BuddyPress: Members-Only Community Pages

> Sends logged-out visitors who open BuddyPress pages (members, profiles, activity, groups) to the login screen, so the community is visible to members only.

- Type: PHP
- Runs: Frontend cl
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: buddypress, private, login
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/buddypress-private-community/

## Code

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

add_action( 'template_redirect', function () {
    if ( is_user_logged_in() || ! is_buddypress() ) {
        return;
    }

    if ( bp_is_register_page() || bp_is_activation_page() ) {
        return;
    }

    wp_safe_redirect( wp_login_url( home_url( add_query_arg( array() ) ) ) );
    exit;
} );
```

## Notes

Registration and account activation pages stay open so new members can still sign up.

## How to use it

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