How to Redirect to BuddyPress Members Page After Visiting Particular Page

I am aware of plugins that redirect user to BuddyPress profile page after login. However, I need a plugin or some guidance on how to redirect an already logged in member to his BuddyPress profile page when he visits a particular page that I choose.

Please respond soon.

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hey there, wainwatkins! Happy Friday!

    Can you give me a few more details on your usage case? What do you want the user experience to look like from their end? Will the visit the page that redirects to their profile for a length of time, or until they do an action? (like clicking or scrolling)? Or will clicking the link to the page you specify take them right to their own profile?

    Thanks!

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hello again!

    Drop this in to your functions.php:

    function redirect2profile(){
    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    if($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php') && is_user_logged_in()){
    global $current_user;
    wp_redirect( get_bloginfo('url') . '/YOURPAGESLUG/'. $current_user->user_login . '/profile/');
    exit();
    }
    }
    add_action('init', 'redirect2profile');

    Replace “YOURSLUGHERE” above with the slug of the page you want to redirect to the profile.

    Take care, and have a great weekend!

  • Dave
    • Site Builder, Child of Zeus

    Great question. I haven’t tried the answer yet, but it made me think of an extended question for this topic.

    What if you wanted to do this same thing but with more locations. Like Page B redirects to the profile.