Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display portion of user bio in membership directory


  • stephunique
    Participant

    @stephunique

    Hello,

    I’d like to display a portion, say the first 60 characters or so of their bio (and a message if they have not filled it out) in their name card in the membership directory. At the moment it only shows their profile picture and their name underneath, and how long ago they were active.

    Thanks in advance to anyone that can help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • @stephunique with the help of this code snippet, you can display the user bio on member directory.

    /**
    * User Bio on member directory.
    *
    * @return void
    */
    function display_user_bio_on_member_directory() {
    if ( ! bp_is_members_directory() ) {
    return;
    }
    global $members_template;
    $member_id = $members_template->member->id;
    $bio = get_user_meta($member_id, ‘description’, true);
    echo ‘<br>’;
    if( ! empty( $bio ) ){
    echo wp_trim_words( $bio, 60, ‘…’ );
    } else {
    echo esc_html( ‘Custom message for user bio is empty’ );
    }
    }
    add_action( ‘bp_directory_members_item_meta’, ‘display_user_bio_on_member_directory’ );


    stephunique
    Participant

    @stephunique

    @imranmd Thank you so much for this, it works perfectly for me on the child theme’s functions.php file of the latest version (4.6.8) of BuddyX theme.


    stephunique
    Participant

    @stephunique

    Hello @imranmd, this solution no longer works and I get an error saying line 13 has a “Syntax error, unexpected token “>”.” (the line that says echo ‘<br>’;)

    Can you help?


    stephunique
    Participant

    @stephunique

    Hey @activadorr thanks for your message. How silly of me, I know about the curly quote issue and didn’t check this. I’ve changed all the quotes to straight quotes and works now. Thank you so much!


    stephunique
    Participant

    @stephunique

    Follow up question:
    Is there a way to change the code to display an excerpt from some other profile field type other than the “WordPress Fields” -> “Biography”? Specifically I am after displaying whatever is in the “Multi-Line text area” field type.

    Thank you in advance to anyone who can help


    stephunique
    Participant

    @stephunique

    Thanks @activadorr for the draft code suggestion. I am not a developer so forgive me for asking this, but how do I find the field identifier? I’ve been trying to find it and the only thing I can find is the field ID, which is a number such as “50”.

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