BuddyDev

Search

[Resolved] BuddyPress Activity Shortcode – Set length (word count) of the text

  • Participant
    Level: Enlightened
    Posts: 39
    yuriix on #43542

    Hello,

    I need to set the length of the text, the number of words. Is it possible to add something to the shortcode to set the word count? Or how could this be handled to adjust the word count only on the shortcode?

    Thank you.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43548

    Hello Yuriix,

    Thank you for posting here. There is no attribute supported by plugin to limit no. of words in an activity. But you can use the filter name ‘bp_activity_excerpt_length’ to limit the character count.

    If you need assistance with the code Please let me know.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 39
    yuriix on #43551

    Hello Keymaster,

    If I use ‘bp_activity_excerpt_length’ it will modify the Word Limit everywhere, I would only need it somewhere, i.e. in certain places where I use the shortcode.

    Thank you

    Regards

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43552

    Hello Yuriix,

    Please use the following code:

    
    /**
     * Excerpt length of activity in shortcode context
     *
     * @param int $length No. of words.
     *
     * @return int
     */
    function buddydev_modify_activity_excerpt_length( $length ) {
    	return 150;
    }
    
    add_action( 'bp_activity_stream_shortcode_before_generate_content', function() {
    	add_filter( 'bp_activity_excerpt_length', 'buddydev_modify_activity_excerpt_length' );
    } );
    
    add_action( 'bp_activity_stream_shortcode_after_generate_content', function () {
    	remove_filter( 'bp_activity_excerpt_length', 'buddydev_modify_activity_excerpt_length', 10 );
    } );
    
    

    Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 39
    yuriix on #43553

    Hello Keymaster,
    Cool, it works perfectly if the user adds something via Activity. Unfortunately, if I add a post, the text is still long.

    https://mag.grafan.cz/m2/

    Regards

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43572

    Hello Yuriix,

    Thank you for the acknowledgment. I will check for post content type activity and will let you know.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 39
    yuriix on #43573

    Hello Keymaster,

    Okay, thank you very much.

    Regards

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43600

    Hello Yuriix,

    Please try to use the following code:

    
    
    /**
     * Excerpt length of activity in shortcode context
     *
     * @param int $length No. of words.
     *
     * @return int
     */
    function buddydev_modify_activity_excerpt_length( $length ) {
    	return 50;
    }
    
    add_action( 'bp_activity_stream_shortcode_before_generate_content', function() {
    	add_filter( 'bp_activity_maybe_truncate_entry', '__return_true' );
    	add_filter( 'bp_activity_excerpt_length', 'buddydev_modify_activity_excerpt_length', 100 );
    } );
    
    add_action( 'bp_activity_stream_shortcode_after_generate_content', function () {
    	remove_filter( 'bp_activity_maybe_truncate_entry', '__return_true', 10 );
    	remove_filter( 'bp_activity_excerpt_length', 'buddydev_modify_activity_excerpt_length', 100 );
    } );
    

    Please let me know if it helps you or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 39
    yuriix on #43610

    Hello Keymaster,

    Perfect, if you could shorten the title (of the created post or added product (Woocommerce)) and it would be complete 🙂

    Thank you very much.

    Regards

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43656

    Hello Yuriix,

    Thank you for the acknowledgment. I will take a look at the title and will let you know.

    Regards
    Ravi

The topic ‘ [Resolved] BuddyPress Activity Shortcode – Set length (word count) of the text’ is closed to new replies.

This topic is: resolved