Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Needed a means of adding a user name to a WP page in a BuddyPress site the other day, easiest approach for this seemed to be a shortcode that the admin could add to the page.
* Add BP username via a shortcode function
* Use in pages or posts?
* For no real reason one can pass a specific user id through
function display_username_in_posts($atts) {
$bp = buddypress();
"id" => '',
), $atts));
if('' == $id ) :
$hnla_user_name = $bp->loggedin_user->userdata->display_name ;
$hnla_user_name = bp_core_get_core_userdata($id);
$hnla_user_name = $hnla_user_name->display_name;
return '<span class="user-display-name"> ' . $hnla_user_name . ' </span>';
add_shortcode('hnla_bp_username', 'display_username_in_posts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.