Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a ‘label’ to a custom profile page


  • groston
    Participant

    @groston

    Based on some user testing, it was suggested that we add a label above certain field in the profile field to describe the usage of several fields (as opposed to having a description beneath just one of the fields). Can someone suggest a way that this can be accomplished?

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)

  • Venutius
    Moderator

    @venutius

    Would you be looking to use an existing label or add a new one, which page?


    groston
    Participant

    @groston

    We want to add a new label. The page would be the Edit Profile page.


    Venutius
    Moderator

    @venutius

    What you can do is overload that pages, the source file is plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php

    Copy this file to themes/your-child-theme/buddypress/members/single/profile/edit.php you can then edit this page to insert your label where you need.


    groston
    Participant

    @groston

    venutius – thank you.

    I am not a WordPress expert, so I need a little more guidance. My guess is that the call to bp_the_profile_field returns the current edit field and that I could create an if clause that would insert some HTML if the field ID (or label) matches the one where I want my label inserted. But this is just a guess – can you please point me in the right direction?


    Venutius
    Moderator

    @venutius

    Yes that sounds about right, the page is doing a loop printing out the profile fields, so you could add an if statement dependent on the field name.

    if ( 'Name' == bp_get_the_profile_field_name() ) {
        //insert label
    }

    groston
    Participant

    @groston

    Sorry for being slow…

    I looked at the source for the page and found that the ID for the field is field_821. I then inserted three lines of code into the edit.php file as shown below (the first line is existing code, at line 22, shown for reference)

    <div<?php bp_field_css_class( 'editfield' ); ?>>
     <?php if ( 'field_821' == bp_get_the_profile_field_name() ) : ?>
       <p>My label here</p>
     <?php endif ?>

    Note: I also tried with the

    And yes, I want this label to appear above the field name. I also realize that simply using <p> may not provide the desired formatting, but to goal now is simply to get the test to appear. What am I doing wrong?


    Venutius
    Moderator

    @venutius

    Small typo in your code, you did not close the div tag, also I note you don’t close the div. When a field has a name like field_821 I’d be worried that it was being dynamicaly incremented for each user/instance so may note be the same for all users. Other than that it’s difficult to suggest anything without seeing your setup direct.

    <div><?php bp_field_css_class( 'editfield' ); ?>>
     <?php if ( 'field_821' == bp_get_the_profile_field_name() ) : ?>
       <p>My label here</p>
     <?php endif ?>

    groston
    Participant

    @groston

    Thanks again for the help! This post, https://buddypress.org/support/topic/how-to-customize-the-order-of-fields-of-registration/, led me to the answer: the function bp_get_the_profile_field_name() returns the ‘friendly’ name of the field, i.e., that which is defined in wp-content\plugins\<my-plugin>\include\users\profile.php as the label parameter for the field.


    Venutius
    Moderator

    @venutius

    Great! glad you sussed it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar