1

By default, when you click on the author in a post, WP directs you to:

example.com/author/sample-user/

However, for BuddyPress users, it makes much more sense that it directs the user to the author's BuddyPress profile page:

example.com/members/sample-user/

Does anyone know how to do this? Thanks!

UPDATE I'm trying with the following codes

add_filter( 'author_link', 'change_author_link', 10, 1  );

function change_author_link($link) {

$link = 'http://asiaforum.club/members/' . $author_ID;
return $link;
}

But I can't seem to get wordpress to retrieve the author's user ID. Any idea on how to do that (or if this method will work)?

1

The following codes worked. I added to my child theme's functions.php

  add_filter( 'author_link', 'change_author_link', 10, 1  );

  function change_author_link($link) {
   $username=get_the_author_meta('user_nicename');


  $link = 'http://example.com/members/' . $username;
   return $link;
 }
0

A more robust approach:

function change_author_link($link) {

   $user_id = get_the_author_meta('ID');

   return bp_core_get_user_domain( $user_id );
}
add_filter( 'author_link', 'change_author_link', 10, 1  );
  • That's great! However, I don't think user ID works with buddypress because the profile link is generated with usernames. That's why my code uses "user_nicename". I suppose simply username works too. When you use user_ID it will only return the numerical ID assigned by the system, which buddy press doesn't recognize – Ashley Liu Aug 22 '17 at 21:32
  • 1
    Read: hookr.io/functions/bp_core_get_user_domain – shanebp Aug 23 '17 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.