Search code examples
phpwordpressbuddypress

Buddypress get full name print to new wordpress page


Referring to How to get username/display name in Buddypress?

I have tried putting this code to an added new page

<?php
$string = bp_get_displayed_user_fullname();
echo $string;
?>

But when i tried previewing the page it prints empty only. Is there something I missed on the plugin to make it working? TIA


Solution

  • bp_get_displayed_user_fullname() will work only on pages, that are displaying some user. That means your profile or profiles of other users. On all other pages you will always see an empty string (forums, ordinary WordPress pages and posts, groups etc).

    To display a name of any user on any page you need to use something like bp_core_get_user_displayname( $user_id ), where $user_id is, obviously, the ID of a user you want the name of.