BuddyDev

Search

[Resolved] Turn activity excerpt into clickable link

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #47967

    Hello Brajesh

    With the latest version of buddypress the activity featured image is a clickable link except the excerpt.

    How can I also turn the excerpt into a clickable link, I have tried the code below but did not work perfectly

     /* Turn blog post activity excerpt into a clickable link */
    function make_excerpt_clickable_for_new_blog_post( $action, $activity ) {
    
        if ( $activity->type == 'new_blog_post' ) {
            $post_id = $activity->secondary_item_id;
            $post = get_post( $post_id );
            
            if ( ! $post ) {
                return $action;
            }
    
            $excerpt = $post->post_excerpt ? $post->post_excerpt : $post->post_content;
            $action = sprintf( '<a href="%s">%s</a>', get_permalink( $post_id ), $excerpt );
        }
    
        return $action;
    }
    add_filter( 'bp_get_activity_action', 'make_excerpt_clickable_for_new_blog_post', 10, 2 ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #47995

    Hi Tosin,
    I will suggest not doing it or if you do still plan to it, make sure the excerpt does not contain html tags.

    Also, where did you find the above code? It is not related to the activity content.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #47997

    Thanks Brajesh

    I will still like to proceed with this, I will really appreciate your assistance with the best solution.

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #48170

    Gentle reminder sir, thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #48181

    Hi Tosin,
    Please feel free to adapt this code as you please.

    
    
    add_filter( 'bp_activity_create_summary', function ( $summary, $content, $activity, $extracted_media ) {
    
    	if ( 'new_blog_post' !== $activity['type'] ) {
    		return $summary;
    	}
    
    	// recreate summary.
    	$summary = bp_create_excerpt(
    		html_entity_decode( $content ),
    		225,
    		array(
    			'html'              => false,
    			'filter_shortcodes' => true,
    			'strip_tags'        => true,
    			'remove_links'      => true,
    		)
    	);
    
    	$permalink = get_permalink( $activity['secondary_item_id'] );
    
    	return sprintf( "<a href='%s'>{$summary}</a>", esc_url( $permalink ) );
    }, 10, 4 );
    

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #48185

    thanks Brajesh,

    This helped

    /* turn activity excerpt into a clickable link */
    add_filter( 'bp_activity_create_summary', function ( $summary, $content, $activity, $extracted_media ) {
    
    	if ( 'new_blog_post' !== $activity['type'] ) {
    	return $summary;
    }
    
    // Get post title.
    $post_title = get_the_title( $activity['secondary_item_id'] );
    
    // Get featured image.
    $featured_image = get_the_post_thumbnail( $activity['secondary_item_id'], 'thumbnail' );
    
    // Recreate summary.
    $summary = bp_create_excerpt(
    	html_entity_decode( $content ),
    	225,
    	array(
    		'html'              => false,
    		'filter_shortcodes' => true,
    		'strip_tags'        => true,
    		'remove_links'      => true,
    	)
    );
    
    $permalink = get_permalink( $activity['secondary_item_id'] );
    
    return "<a href='" . esc_url( $permalink ) . "'>" . $post_title . "</a>" . "<a href='" . esc_url( $permalink ) . "'>" . $featured_image . "</a>" . "<a href='" . esc_url( $permalink ) . "'>" . $summary . "</a>";
    
    }, 10, 4 );
  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #48193

    Hi Tosin,
    You are welcome.
    good to see that you have added title/thumbnail. I would slightly update it to check for the existence of thumbnail image.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved