I'm using the buddypress hovercards plugin and Im dislaying some profile info as well as the latest status update. If a user posts a long status, it will run out of the hovercard div field. How can I properly truncate this?

<div class="update">
  <strong><?php _e("Last update", 'bp-hovercards'); ?></strong>
  <?php bp_member_latest_update( 'length=10' ) ?>

You can filter 'bp_get_activity_latest_update_excerpt'. Sample code, not tested, you will need my function utf8_truncate():

add_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt' );

function wpse_56860_trim_buddypress_excerpt( $excerpt )
    // Number of characters to show. Adjust this to your needs.
    $length = 80;

    // Fix BuddyPress’ wrong quotes.
    return _x( '&#8220;', 'opening curly double quote' ) 
        . utf8_truncate( $excerpt, $length )
        . _x( '&#8221;', 'closing curly double quote' );

Download as complete plugin.


There is an alternative: create a hovercard.php in your theme, the plugin will use this file then instead of the same named file in the plugin directory. In hovercard.php change the line bp_member_latest_update( 'length=10' ) to get the proper length or add the filter at the top of the file and remove it after the last endif;:

<?php if ( bp_has_members( "include={$_POST['userid']}&max=1") ) : 
add_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt', 8 );
// lots of stuff
<?php endif; 

remove_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt', 8 );
  • I'm sorry. I would love to give this a try but I don't know where to place it. Can you please tell me where in my php files to place these snippets? Do I put them in my theme's functions.php or the plugin's php or..? – Androliyah Jun 28 '12 at 22:35
  • See my update. You can download the complete code as a plugin and install it on your blog. – fuxia Jun 28 '12 at 22:38
  • I've uploaded it into my plugins folder but can't see it in the plugins list. Is that supposed to happen? Also, I need to only truncate the activity that is shown in a certain plugin (hovercards plugin) – Androliyah Jun 28 '12 at 22:59
  • Hm, it should be visible. Did you save the raw file as bp-last-activity-shortener.php? – fuxia Jun 28 '12 at 23:04
  • Well yes but that is inside of a folder. Should I upload it to plugins without a folder? – Androliyah Jun 28 '12 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.