display username in members directory
-
I’m trying to display the sign up username in the directory but it’s showing empty space instead
Here’s part of the code:
<div class="item-title">
<a href="<?php bp_member_permalink() ?>"><?php bp_displayed_user_username() ?></a>
<?php if ( bp_get_member_latest_update() ) : ?>
<span class="update"> - <?php bp_member_latest_update( 'length=10' ) ?></span>
<?php endif; ?>
</div>Can someone let me know what I did wrong?
[wordpress2.9.2+buddypress1.2.1]
-
No need to edit a template file for this.
Try adding the following in your theme’s functions.php:
function my_member_username() {
global $members_template;
return $members_template->member->user_login;
}
add_filter('bp_member_name','my_member_username');I placed it in “plugins” and it works great! It’s a slow process but I’m learning from these snippets.
Is there a reference guide where you pulled these from for those of us not as verse with the different variables used?
I’ll try to get the same result for the comment section to match the name used in the members directory.
Thank you so much!
Yes, it’s called manually going through the code
Try looking through the various bp-COMPONENT-templatetags.php files.
There’s also the codex – codex.buddypress.org – but it needs a little TLC.
In reference to:
No need to edit a template file for this. Try adding the following in your theme’s functions.php:
function my_member_username() {
global $members_template;
return $members_template->member->user_login;
}
add_filter(‘bp_member_name’,’my_member_username’);
I don’t want to mess anything up… There are 67 lines of code, in what area of the theme’s functions.php code do I paste the above mentioned code into
Anywhere. Top, bottom, wherever.
It’s always good to organize items in your theme’s functions.php.
Snap. That code crashed my site. I just want it so people’s full names aren’t showing up here:
http://oneword.com/activityThanks!
“Crashed” your site, how? White page? Probably you made an error putting the code into functions.php.
Yes. White page. Error putting the code in? Obviously.
Haha. Okay, apparently the problem is that I already had it in there… So it works great in the members directory, now how can I extend that to the activity feed? Thanks.
I’d like to know how to extend it to the activity feed as well as bbPress. I have bbPress integrated with WordPress and the users’ first names are appearing instead of their usernames.
If you want to display both usernames and display names you can use this version in your theme’s functions.php:
/*Display Username and display name in Directory */
function my_member_username() {
global $members_template;
if ( empty($members_template->member->fullname) ) {
$members_template->member->fullname = $members_template->member->display_name;
}
$toReturn =$members_template->member->fullname .’ @’.$members_template->member->user_login;
return $toReturn;
}
add_filter( ‘my_member_username’, ‘wp_filter_kses’ );
add_filter( ‘my_member_username’, ‘stripslashes’ );
add_filter( ‘my_member_username’, ‘strip_tags’ );add_filter(‘bp_member_name’,’my_member_username’);
Can this code be adapted to show BOTH the Display Name and the Username together next to comments left on the main blog?
This is so that people can see both the regular Display Name of whoever has left a comment, but also the user name so they can add an @ message addressed in the correct way.
This is related to a query I posted here:
The solution from @lenasterg works very well in the members directory and search results, but I would still like to be able to do the same on the comments for the main blog as well.
I’ve been trying to write a hook for functions.php to do this but I’m getting nowhere. Any help would be appreciated.
A further question on the solution from @lenasterg:
Is it possible to add another filter which changes any spaces in usernames into hyphens?
I have some users who signed up before spaces in usernames were automatically turned into hyphens, so I need it to display @mr-smith instead of @mr smith.
Thanks for the help here’s a little snippet that checks for full name, and if none exists displays the username
`
/* Display Nice Name in Directory */
function my_member_username() {
global $members_template, $bp;
$display_name = $members_template->member->display_name;
if ($display_name) {
return $display_name;
} else {
return $members_template->member->user_login;
}
}
add_filter(‘bp_member_name’,’my_member_username’);`
I followed 2 steps to successfully display usernames in the BP members directory & other pages instead of default Display names:
1st step was to install the BP Usernames only plugin: https://wordpress.org/extend/plugins/buddypress-usernames-only/
This replaced display names across the site by usernames however, when I used the search box on the members directory to search a member, it returned results with members display names again and not usernames. To resolve this, I additionally followed step 2 explained here: http://customwebdesignseo.com/activity/p/3002/The code from @lenasterg worked well. Anyone know how to separate the name and @username so instead of one lone string “Name@username” you can have two lines like this:
Name
@usernameThanks
- The topic ‘display username in members directory’ is closed to new replies.