How to change the permalinks for BuddyPress activity, blogs, friends, members, etc.

To change the permalinks for BuddyPress activity, blogs, friends, members, etc., you can use the bp_core_get_user_domain() function. This function returns the URL of the user’s profile page, with a customizable path appended to the end.

Here’s an example of how you can use the bp_core_get_user_domain() function to change the permalinks for BuddyPress activity, blogs, friends, and members:

// Change the permalinks for BuddyPress activity, 
// blogs, friends, members, etc.
// More snippets at wpunplugged.com 

/**
 * @param string $user_domain The user's profile URL.
 * @param int $user_id The ID of the user.
 * @param string $user_nicename The user's nicename.
 * @param string $user_login The user's login name.
 * @return string The modified user's profile URL.
 */
function my_bp_custom_permalinks( $user_domain, $user_id, $user_nicename, $user_login ) {
    // Change the permalink for the activity tab
    $user_domain = str_replace( 'activity', 'my-custom-activity-slug', $user_domain );

    // Change the permalink for the blogs tab
    $user_domain = str_replace( 'blogs', 'my-custom-blogs-slug', $user_domain );

    // Change the permalink for the friends tab
    $user_domain = str_replace( 'friends', 'my-custom-friends-slug', $user_domain );

    // Change the permalink for the members tab
    $user_domain = str_replace( 'members', 'my-custom-members-slug', $user_domain );

    return $user_domain;
}
add_filter( 'bp_core_get_user_domain', 'my_bp_custom_permalinks', 10, 4 );

In this example, the permalinks for the activity, blogs, friends, and members tabs are changed to my-custom-activity-slug, my-custom-blogs-slug, my-custom-friends-slug, and my-custom-members-slug, respectively. You can modify this code to change the permalinks to whatever you want.

To add this code to your site, you can add it to your theme’s functions.php file.

Note that this code assumes that you have the BuddyPress plugin installed and activated on your WordPress site. If you don’t have BuddyPress installed, you will need to install and activate it before you can use the bp_core_get_user_domain() function.

In addition to changing the permalinks for the activity, blogs, friends, and members tabs, you can also change the permalinks for other BuddyPress components by using similar code. For example, you can use the bp_get_groups_root_slug filter to change the permalink for the groups component, or the bp_get_messages_slug filter to change the permalink for the messages component. You can find a list of all of the available filters in the BuddyPress documentation.

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *