Skip to content
Advertisement

Change default user profile URL – BBpress Plugin

Bbpress WordPress Plugin have default link user profile url. The link like this: www.example.com/forum/users/(username)

The main purpose in nutshell is: I want to change the url.

Actually, I found the solution but its not perfect. The code like this:

function user_profile_link(){
    $url = 'http://localhost/example.com/profile/';
    $author_id = bbp_get_reply_author_id();
    $user_info = get_userdata($author_id);
   
    echo '<a href="'.$url.''.$user_info->user_login.'"> '. $user_info->display_name.' </a>';

}
add_filter('bbp_get_user_profile_url', 'user_profile_link');

Yes, the code working well. But the outcome is, the user profile URL not replaced and there is double URL like this image below:

image1

I think the problem solved if I display: none it. The code like this:

<style>
.bbp-author-link{
    display: none;
}

</style>

But there is one problem. The new URL that I make appeared beside the breadcrumbs like this image:

image2

I want to remove the link that appeared beside the breadcrumbs. Is there any solution? Any help is appreciated. Thank You

Advertisement

Answer

In a filter hook, you normally have to override the current value by returning it. Therefore try returning the new value by using the function you already created. It may remove the duplicate.

Also, use site_url() instead of $url variable because there will be issues when you use a hardcoded URL.

function user_profile_link(){
    $author_id = bbp_get_reply_author_id();
    $user_info = get_userdata($author_id);

    return site_url()."/profile/".$user_info->user_login;

}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement