BuddyDev

Search

[Resolved] Add Read More link to buddypress activity excerpt

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

    Hello,

    Please how can I add a new Read More link after the new_blog_post activity type while using the buddyblog pro plugin.

    I have tried this code but did not work

     function bp_activity_read_more() {
        if ( bp_is_active('activity') ) {
            global $activities_template;
    
            if ( 'new_blog_post' === $activities_template->activity->type ) {
                $activity = $activities_template->activity;
    
                $post_id = $activity->primary_link;
                $excerpt = bp_create_excerpt( $activity->content );
                $url_ad = get_permalink( $post_id );
    
                echo '<div class="activity-content">';
                echo '<p class="activity-excerpt">' . esc_html( $excerpt ) . '</p>';
                echo '<div class="read-more"><a href="' . esc_url( $url_ad ) . '">Read More</a></div>';
                echo '</div>';
            }
        }
    }
    add_action( 'bp_before_activity_loop', 'bp_activity_read_more' );
     
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #50260

    Hello Tosin,

    Try action ‘bp_activity_entry_content’ and fix your post_id.

    
     $post_id = $activity->primary_link;
    
    

    Regards
    Ravi

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

    Thanks Ravi,

    This code below worked for me

     function bp_activity_read_more( $content, $activity ) {
        if ( 'new_blog_post' === $activity->type ) {
            $post_id = $activity->secondary_item_id;
            $post_url = get_permalink( $post_id );
    
            // Append the "Read More" link to the content
            $read_more_link = '<div class="read-more"><a href="' . esc_url( $post_url ) . '">Read More</a></div>';
            $content .= $read_more_link;
        }
    
        return $content;
    }
    add_filter( 'bp_get_activity_content_body', 'bp_activity_read_more', 10, 2 ); 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #50296

    Hello Tosin,

    Thank you for the acknowledgement. I am glad that you fixed the problem on your own.

    Regards
    Ravi

The topic ‘ [Resolved] Add Read More link to buddypress activity excerpt’ is closed to new replies.

This topic is: resolved