BuddyBlog – Activity Stream excerpt limit – How to reduce the amount of words

Tagged: ,

  • Participant
    Level: Enlightened
    Posts: 56
    John B on #37546

    I have add the following code to my functions.php to limit the number of words on the blog pages. This code works great.

    function custom_excerpt_length( $length ) {
    	return 32;
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

    Do you know of a way to limit the amount of words that are displayed for the blog excerpt on the Activity Stream?

    Currently there are more than 50 words that appear on the Activity Stream when a new blog post is created. I need to limit this to 32 words or so.

    Is this possible?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #37565

    Hello John,

    Thank you for posting. Filter ‘excerpt_length’ used by WordPress on the post archive page. If you want to restrict activity excerpt length please use the following filter:


    Please do let me know if it works or not.


  • Participant
    Level: Enlightened
    Posts: 56
    John B on #37735

    This is how to limit the number of characters, while ensuring the thumbnail remains present.

     function 5_activity_content_body( $content, $activity ) {
        $content_length = 42;
        if ( 'new_blog_post' == $activity->type ) {
            $images = extractImageFromContent($content);
            $_content = (strlen($content) > $content_length) ? substr($content, 0, $content_length).'...' : $content;
            if(!empty($images)) {
                $_content .= implode("", $images);
            return $_content;
        return $content;
    add_filter( 'bp_get_activity_content_body', '5_activity_content_body', 10, 2 );
     function extractImageFromContent($html) {
        preg_match_all('/<img.*?src=[\'"](.*?)[\'"].*?>/i', $html, $matches);
        return ($matches[0]) ? $matches[0] : array();

You must be logged in to reply to this topic.

This topic is: not resolved