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.

    • 2,100 pts
      9,660 pts
      LEVEL 27

    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

    • 63 pts
      618 pts
      LEVEL 6

    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

    • 53 pts
      4 pts
      LEVEL 0

    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.

    Jack Kitterhing
    • 13,175 pts
      20,391 pts
      LEVEL 30

    Hi there, @frankwarwick,

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

    Kind Regards

    • 50 pts
      25 pts
      LEVEL 2

    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?


We pride ourselves on our level of customer support and responsiveness to member requests. Your WordPress experience will never be the same

Become a member

  • PayPal Partner