Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Display an excerpt of a profile field (Bio)

  • Avatar of cyndimarie
    cyndimarie
    Participant

    @cyndimarie

    I am modifying my members-loop.php to display some additional profile fields. I want to show the “Bio” field, however I want to limit the length of it to make an excerpt.

    Here’s what I currently have:
    <span class="short-bio"><?php echo bp_member_profile_data('field=Bio...'); ?></span>

    How can I make it so that it only displays a certain length of it (like 200 characters or something)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Avatar of danbp
    danbp
    Moderator

    @danbp

    Hi @cyndimarie,

    here’s a filter you can use on the members directory. The bio excerpt will only show up for logged in users. Put this function into your theme’s functions.php file

    function bpfr_bio_length() {	
    
    if ( is_user_logged_in() ) :
    
    	$profile_bio = bp_get_member_profile_data( 'field=Brief Biography&user_id='.bp_loggedin_user_id() );	
    	
    	if ( strlen($profile_bio) > 200) :  //adjust to your need
    	$profile_bio = substr($profile_bio, 0, 200).'...'; //adjust to your need
    	endif;
    	
    ?>
    
    <span class="short-bio"><?php echo $profile_bio; ?></span>
    <?php
    endif;
    }
    add_action( 'bp_directory_members_item', 'bpfr_bio_length' );

    If you prefer to modify the members-loop.php file, create first a child theme, and then insert this piece of code at the appropriate place

    $profile_bio = bp_get_member_profile_data( 'field=Brief Biography' );
    
    if(strlen($profile_bio) > 50))
      $profile_bio = substr($profile_bio, 0, 50).'...';
    
    <span class="short-bio"><?php echo $profile_bio; ?></span>

    First solution may be better… ;-)

    Avatar of cyndimarie
    cyndimarie
    Participant

    @cyndimarie

    Thanks so much! I ended up using the second piece of code and it worked perfectly (minus the extra parenthesis).

    Avatar of @mercime
    @mercime
    Keymaster

    @mercime

    @danbp merci!

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

You must be logged in to reply to this topic.