You are right, It will work on members page only, as it uses $bp->displayed_user which is set for member pages only.
You can accomplish the same by using function
“bp_core_get_username” on any of the pages. take a look at the function definition.
Thanks for the suggestion, however “bp_core_get_username” doesn’t yet return (display) anything. I wonder if there’s anything changed from version 1.2
I think this “bp_core_get_username” is used only for one member. This doesn’t work on members-loop.php where it should list member names and avatars on the Members Directory.
The function should be something equivalent to
<?php bp_member_name() ?>
But instead of member nickname it should return login ids of members.
I just found the following custom function, but I wonder why this function is not built in by default.
https://buddypress.org/forums/topic/display-username-in-members-directory#post-41928
Does anyone know how I can modify this code into a new function, rather than overwriting bp_member_name? I’ve tried add_function instead, but didn’t work. Preferably I’d like to create a new function called bp_member_username.
function my_member_username() {
global $members_template;
return $members_template->member->user_login;
}
add_filter('bp_member_name','my_member_username');
If using bp_core_get_username, make sure you do the following:
– echo the result. Unlike bp_displayed_user_username(), it does not echo automatically. Ie
<?php echo bp_core_get_username( $user_id ); ?>
– Feed it $user_id as an argument. If you don’t, the argument will return false.
See bp-core.php, around line 1005, for the definition of the function, as Brajesh suggested.
To my understanding and testing experience, the following doesn’t return list of usernames of members on members-loop.php
<?php echo bp_core_get_username( $user_id ); ?>