BuddyX

1 min read · 213 words

Can I redirect non-logged-in users to a specific page in BuddyPress?

Can I redirect non-logged-in users to a specific page in BuddyPress?

Yes, but how you do it depends on which visitors you mean. BuddyPress splits into two separate problems here: redirecting people based on role after they log in or out, and redirecting people who aren’t logged in at all. The first has a ready plugin; the second is a small code snippet.

Role-Based Redirects: BuddyPress Redirect

BuddyPress Redirect handles login and logout redirects through the admin dashboard, no code required. Send members to their personal profile, their personal activity stream, sitewide activity, or a custom URL, configurable per user role, so admins and regular members can land somewhere different after logging in.

Free, still updated (v2.2.0, updated within the last few months), requires BuddyPress to be active.

Redirecting Non-Logged-In Visitors

This one isn’t covered by a settings screen, it’s a small snippet in your theme’s functions.php or a custom plugin, using the bp_template_redirect hook:

function custom_non_loggedin_redirect() {
    if ( ! is_user_logged_in() ) {
        bp_core_redirect( 'https://example.com/redirect-page' );
    }
}
add_action( 'bp_template_redirect', 'custom_non_loggedin_redirect' );

Replace the URL with wherever you want non-logged-in visitors sent, a login page, a landing page, whatever fits your site.

If you’re not comfortable editing theme files directly, a code-snippets plugin (WPCode, Code Snippets) lets you add this safely without touching functions.php, and without losing the change on a theme update.

Reading
1 min · 213 words
Published
May 18, 2023
Shashank Dubey
BuddyX contributor

Writing about WordPress communities, BuddyPress, BuddyBoss, LMS plugins, and the business of paid communities.

Keep reading

More from the BuddyX blog

Browse all posts on community, WordPress, BuddyPress and the studio of plugins behind BuddyX.