Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

  • @cyndimarie

    Participant

    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)
  • @danbp

    Participant

    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… 😉

    @cyndimarie

    Participant

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

    @mercime

    Participant

    @danbp merci!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Display an excerpt of a profile field (Bio)’ is closed to new replies.
Skip to toolbar