I am now able to block buddypress pages and redirect users to a page I choose

After a long saga I think I finally solve this mystery. I only took some guesses and got it working but if someone has a more elegant way of doing this then great! It is working as expected but I am not a coder.

Found my solution here

I modified Richie_KS codes since I want to disallow logged out users from all my buddypress pages and redirect them to my login page instead.

In functions.php I add this
function bp_guest_redirect() {
global $bp;
if ( bp_is_activity_component() || bp_is_groups_component() || bp_is_blogs_component() || bp_is_page( BP_MEMBERS_SLUG ) ) {
// enter the slug or component conditional here
if(!is_user_logged_in()) { // not logged in user
wp_redirect( get_option('siteurl') . '/signup' );
} // user will be redirect to any link to want

This code also killed another bird.

I use BuddyPress Daily Child 3.9.6 theme and it works perfectly when a logged out user attempt any buddypress page searches using the sidebar search option. They are only redirected to my login page.

Any corrections to my code if necessary will be appreciated. I know if it ain't broke I shouldn't fix it but I hate to end up with problems down the road due to my poor coding skills.


    Nice work drdave!

    Look at you go with your own custom theme function :) I'll ask a theme designer or two to stop by and doublecheck, but it looks good and as you say - it does exactly what you're wanting in this scenario.

    Nicely done and thanks for sharing! :D


    Seems so much cleaner than using a plugin imo unless, or until membership plugin can provide a fix. I was looking at Buddypress Private Community for a while but thought it might clash with membership. I'll definitely keep an eye out.

    Thanks masonjames

    • Pro
    • 4
    • #18,117

    Just found this topic thanks to Google and it kinda saved my life. Just one thing though: for me it doesn't seem to work with member pages... Any idea why?
    thanks again.

    Frank Warwick
    • Elite
    • 67
    • #1,668

    This is great, added it, tested it and it works first time, thanks @drdave

    Jack Kitterhing

    Hi there, @frankwarwick,

    Awesome, glad to hear that worked for you! :)

    Kind Regards

    • 25
    • #4,730

    I have tried adding this code to my theme functions.php file but It appears to be doing absolutely nothing?! All i changed was removing the <?php ?> start and end tags, and changed the url to redirect to. What am I doing wrong?

Join 368087 happy members

Get access to our entire collection of epic plugins, astonishing themes & genius support

Become a member