How to display BuddyPress extended profile data on every page

BuddyPress is a software add-on that extends WordPress into an online community, which is great for creating your own social networks. I’m just finishing up a project at work where I’m using it to build out our new Intranet and it’s been fun working with it.

That said, I found that I was having trouble with displaying the extended field data that BuddyPress offers because its functionality was constrained to usage on pages of our site that was using their engine.

Normally, when wanting to display field data, you’d add the following PHP code to your template and Bob’s your uncle:

  <?php bp_profile_field_data('field=FIELDTITLE'); ?>

The problem is that it only displays the field data on profile pages and other pages that are specific to BuddyPress’ functionality, like forums, groups, and the like.

On the sidebar for my site, there’s a section similar to the profile widget on LinkedIn, where it shows your avatar, name, and job title. It’s the job title that wasn’t displaying everywhere when using the code above.

The solution…using xprofile_get_field_data to fetch the field data for the logged-in user.

Replace FIELDTITLE with your field name:

  <?php echo ' ' . xprofile_get_field_data( 'FIELDTITLE', bp_loggedin_user_id() ); ?>

Worked like a charm. Now the job title for this young intern now displays anytime he’s logged into the site, whether it’s in the header’s menu:

BuddyPress field display on all pages example

…or the left sidebar:

BuddyPress field display on all pages example 2

I gotta admit, after all these years, I still love this kind of work.

Have fun!

Archived under:
This site uses cookies to collect basic info to help improve your experience. Read my Privacy Policy Accept