Displaying certain profile fields on your members profile page

This post is updated for BuddyPress 1.5!

Showing certain profile fields on a member profile has become really easy since 1.2. By adding a simple code snippet to your member-header.php file, you can display certain fields that are important in your community. With the help from Boone I’ve modified this snippet to only show when the field is actually populated with information. Here’s a quick guide on how to set this up:

Step 1: Move the file bp-default/members/single/member-header.php to your Child Theme folder

Like always you need to move over the template to your Child Theme first, to get this working. Make sure that you keep the folder structure intact when copying over the template (so the file stays in the members/single/ directory.

Step 2:  Add the code snippets to the member header file.

Open up the file, and around line 28 (right after the closing “item buttons” div tag) add the following:

<div id="member_profile">
    <div class="profile_fields">Category: <span><?php bp_profile_field_data( 'field=Category' );?></span></div>
    <div class="profile_fields">Playing Age: <span><?php bp_profile_field_data( 'field=Playing Age' );?></span></div>
    <div class="profile_fields">This Actor Is Currently: <span><?php bp_profile_field_data( 'field=Availability' );?></span></div>
</div>

In the example I’ve used a few profile fields and I’ve added some basic CSS styling. You can replace the profile fields name with your own fields to get everything working. Keep in mind that the field name is case sensitive and that it will only be shown when filled in.

Step 3 (optional): Add some CSS styling

If you keep the same structure as in the snippet, here’s some CSS you can add to your stylesheet.

div#member_profile {
	margin-bottom: 15px;
	margin-top: 15px;
}
.profile_fields {
	color: #777;
	font-weight: 500;
	padding-bottom: 2px;
	padding-top: 2px;
}
.profile_fields span {
	color: #444;
	font-weight: 700;
}

Result:
Screen shot 2011 03 28 at 3.58.21 PM Displaying certain profile fields on your members profile page

Update: Only show a field when it’s filled in

In the comments Onyx asked if it was possible to hide these fields when they are not filled in. This can be done by doing a conditional check to see if the profile field has a value. Here’s the code snippet with a simple example:

<?php if ( $data = bp_get_profile_field_data( 'field=Country ' ) ) : ?>
<div class="profile_fields">
         Country: <span><a href="http://cfcommunity.net/members/?s=<?php echo $data ?>" title="<?php echo $data ?>">
<?php echo $data ?></a></span>
</div>
<?php endif ?>

That should to the trick! Props to Boone who helped me out with this a while back!

BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

Something about bowe

BuddyPress fanatic, WordPress Theme designer and MultiSite community builder. Proud co-founder of PressCrew. Loves to use awesome in every sentence. Often described as a Dutch Treehugging Hippie.

41 Responses to Displaying certain profile fields on your members profile page

  1. Daniel May 2, 2011 at 5:33 am #

    Thank you very much for this tutorial ! Did exactly how described and works perfect , Could you tell me how to use it with checkboxes or datepicker data ? this code is giving me weird results when I use them , I’ve read somewhere that the code should unserialized but I have never found how -:(

    • bowe May 18, 2011 at 10:56 pm #

      I think it’s not currently possible to display those.. At least I don’t know how :(

  2. aljuk May 11, 2011 at 5:25 pm #

    I’m really liking your site, getting some useful info here!

    Regarding the profile fields pull – this is a longshot but…

    I’m using BP Privacy, and looking for a way to determine the display of profile fields in the user’s page header dependent on their privacy settings in BP Privacy. I was hoping it would be * easy * along the lines of if(some privacy function is true) {echo display code} but it’s trickier than that. I was just wondering if you had played around with BP Privacy at all and might have any suggestions. A long shot I know…

    • bowe May 18, 2011 at 10:58 pm #

      Mm… No I have not.. It’s a very good question though, and like to get it answered :) Please let me know if you find out ok? Then I can update the trick as well :)

  3. OnYx June 4, 2011 at 5:00 am #

    Hey this is great! I want to do a little spin on it… I want to do an “if else” statement depending on the value of the field value for example “if field(City)= Hawaii” echo “Aloha!” but im not sure how to get it done..

    • bowe June 5, 2011 at 2:14 pm #

      Great question.. I’ve updated the trick and given a code example on how to pull this off! Let me know if it works for you :-)

      • OnYx June 8, 2011 at 9:04 pm #

        Thank you Bowe, but that’s not what I was asking, maybe I wasn’t clear enough… What I was looking for was to display conditional content depending on xfields values for example if “xfield State” = “Hawaii” to echo out “Aloha Bowe” I manage to do this with the following code

        the only issue I’m running with this is that it doesn’t work on the activity page, not sure why… any idea why it doesn’t work on activity page?

  4. OnYx June 8, 2011 at 9:05 pm #

  5. OnYx June 8, 2011 at 9:07 pm #

    if (bp_get_profile_field_data(‘field=State’) == ‘Hawaii’) :
    echo “Aloha Paul!”;
    endif

  6. shanebp June 10, 2011 at 3:43 pm #

    Re serialized profile data:

    $value = bp_get_profile_field_data(‘field=some_serialized_field’);
    $value = bp_unserialize_profile_field($value);

  7. shanebp June 10, 2011 at 3:58 pm #

    Re not working on activity page:

    You need to pass the member’s id

    global $bp;
    $member_name = $bp->loggedin_user->fullname;
    $member_id = $bp->loggedin_user->id;
    if ( bp_get_profile_field_data( ‘field=State&user_id=’ . $member_id ) == ‘Hawaii’)
    echo “Aloha ” . $member_name;

  8. abbey July 28, 2011 at 10:33 pm #

    Hi, i will like to display some profile field at the members profile page, i know i can do that by adding the code to members-header.php, but how can i put a link, so that if the field is not filled by the member it will just show let say “add your Country” and when click it will just go to the place where he can fill the field

  9. abbey August 24, 2011 at 5:36 pm #

    Any help??

  10. AllMad.org Ranting September 7, 2011 at 5:40 pm #

    Anyone know how I could add bbPress post count, as well?

  11. Lex October 18, 2011 at 3:48 am #

    This doesn’t work for me. It retrieves no value. Will this still work on BP 1.5? Thanks.

  12. Tahir Taous November 20, 2011 at 7:36 pm #

    This code is not working in BuddyPress 1.5. It retrieves no value for me. i want to display some fields, please help.

  13. Sakakeeny1Pavlikowski November 29, 2011 at 2:27 am #

    With a brand new imaginative team on board they will slowly and gradually began to transform the emblem in to a British after which your global famous design and style firm. T.co The business started in the early on Seventies simply by 1 person, Roger Saul. They start making extravagant leather-based belts from the storage of their mom’s or dad’s home with his or her mom’s or dad’s support these folks were before long delivering fashionable trend boutiques, first inside london and after that throughout Rome as well as New York.

  14. Rafsan Ratul November 29, 2011 at 12:35 pm #

    Can’t get the script working!!!!!! :'(

    I did all as you said….I want to display the field “College” which i created using the “profile fields” option in Buddypress
    I edited it like this :(note: I can’t do programming)

    College:

    Only the “College: ” is displayed but it doesn’t display which College even after filling the “college”field in “edit profile”

    :'( please help me

    • Rafsan Ratul November 29, 2011 at 12:41 pm #

      Can’t get the script working!!!!!! :’(

      I did all as you said….I want to display the field “College” which i created using the “profile fields” option in Buddypress
      I edited it like this note: I can’t do programming)

      College:

      Only the “College: ” is displayed but it doesn’t display which College even after filling the “college”field in “edit profile”

      :’( please help me

  15. Iqbal December 2, 2011 at 7:42 pm #

    this doesn’t work for multi select, or checkbox? any idea?

    • Elliot February 3, 2012 at 12:02 pm #

      Hi,

      It shows array when using multi-choice.

      Try using bp_member_profile_data instead of bp_profile_field_data

      Works for me now :)

      Elliot

      • Sabrina May 17, 2012 at 12:12 pm #

        hi Elliot,

        It did the trick but it doesn’t work when i put a id of the field in.

        so this works:
        but this doesn’t:

        • Sabrina May 17, 2012 at 3:41 pm #

          it didn’t show the code so here it is.

          so this works: bp_member_profile_data( ‘field=Soort stage’ );
          but this doesn’t: bp_member_profile_data( ‘field=12′ );

  16. Chris January 27, 2012 at 9:27 pm #

    @Bowe – smallish error, i think the section title near the end of your post should say “Update: Dont leave crumbs when the field isn’t entered” :)

    If you wanted to hide it to logged out members, You’ve written an unnecessary slightly complicated hack, considering all you had to do was wrap it in is_loggedin :) lol but you know that, so i’m assuming it’s an error?

    • bowe February 10, 2012 at 12:11 pm #

      Thank you Chris! I typed the wrong header title indeed. Eagle eyes! It’s fixed now!

  17. Vanima February 11, 2012 at 12:46 pm #

    Hi Bowe

    Nice trick. As I asume you have some experience with the whole buddypress stuff you may be able to help me with a huge problem I’m facing.

    I’d like to change the xprofile-fields to have profile fields for a couple (not all fields but a few). For example if there’s the question:
    How old are you.
    Here I would like to have to dateboxes instead of one. So their must be two in the registration and in the actual profile.

    Do you have any idea how to manage this?

    Thanks a lot and I really like your great tips

    Vanima

  18. Ludu March 20, 2012 at 8:02 pm #

    hello i am using buddypress with customize theme.

    my “REPLY” on the Activity streem is not working it always leed to 404 (page not found)
    Can anyone assist me. how i can get reply on comment on the Activity streem working.

    comment on blog and post works . Only Activity stream reply not working. Comment working.
    Have tried alot. but nothing

  19. Nate April 2, 2012 at 1:07 am #

    Anyone got a simple solution to display the current users name on any page within buddypress?

  20. kumo April 3, 2012 at 6:02 pm #

    I’im using your code to show the user name and birthday, but the birthday shows in the format yyyy:mm:dd 00:00:00 , I want the date to show in the format “yyyy Month dd” like in profile page.. any Idea how can I do that?

  21. how to work from home online April 13, 2012 at 10:28 pm #

    Amazing publish! You might like to contain a number of social links on your own web page and then we may talk about your current products on the web. I usually reveal how to work from home online at how to find jobs on elance as well as I have seen a lot of accomplishment from introducing social links in order to our blog.

  22. imwrong May 3, 2012 at 7:12 pm #

    Hello everyone. I’ve used your tip successfully, but I have another question: I have some groups and users in these groups. Is there a way to show some xprofile field in the group member list? bp_profile_field_data doesn’t seem to work.

    • Patricia May 30, 2012 at 10:40 am #

      This is my first put up on this web site and all i can say is thank you for all these useful dletias! If you enable, I would prefer to use some of your content. I publish articles for post directories as my portion time career. I\’m willing to refernce your internet site in these posts. Kindly get back to me by way of email ASAP.

  23. how to all natural micro-dermabrasion May 23, 2012 at 9:44 pm #

    I think your social media sharing buttons are not working here this

  24. Cpo June 13, 2012 at 2:13 am #

    @imwrong. Did you ever get your answer on displaying member info in the group member fields?

  25. Mike H June 21, 2012 at 12:34 pm #

    I’ve used to create custom profile css for members. Just like Group-CSS..
    Check it out: Here!
    Great Tutorial. =D

  26. Ian Applegate July 4, 2013 at 9:55 pm #

    Hi there – the check to see if a user has filled in the field works great, but as soon as I try and include two different fields to check against, the page breaks. Is it possible to run this check on multiple fields?

  27. hugh August 26, 2013 at 8:36 pm #

    My bad. The files are still in the same structure. I overwrote the files when I upgraded my theme.
    Thanks!

  28. Miriam September 5, 2013 at 8:15 pm #

    Thank you for this helpful entry! i’m just beginning with BP: how can I find out in which file i can change the display of the profile-fields for the listing of the members? i don’t want that just the username und avatar is shown there, the birthday and other fields should also be shown.

  29. rafi October 19, 2013 at 2:48 pm #

    The CSS where can i add can i give me the parth

    same like Step 1 (Move the file bp-default/members/single/member-header.php to your Child Theme folder)

  30. akaoshi1 January 10, 2014 at 11:12 pm #

    Hi thanks for the great tip, can you please help me, on my user header i have displaying their bio info but the text info gets long and i would like to limited it to 250 words on their header any idea how i can do this,

    many thanks

  31. Carl Hassett January 28, 2014 at 5:13 pm #

    Hello – I dont know if you are still taking question on this topic, but thank you for the tricks! I’m trying to figure out how to make a profile field activate a ‘style.css modification’ else where in the site? I have the code to add different color boarders to the users avatar through my child themes style.css, but I don’t know if its possible to activate the colored boarder depending on one of the options the user chooses in their custom profile field? It looks like the code above can be tweaked to accomplish this but I’m not sure if that’s true. Thanks for your time!

Leave a Reply