How to show activity comment count to logged in users only in BuddyPress

To show the activity comment count to logged-in users only in BuddyPress using functions.php, you can use the bp_activity_get_comment_count function in your theme’s functions.php file or in a separate plugin file. This function returns the number of comments on an activity item.

Here’s an example of how you can use the bp_activity_get_comment_count function to show the activity comment count to logged-in users only:

// Show activity comment count to logged in users only in BuddyPress
// More snippets at wpunplugged.com 

function my_custom_activity_comment_count() {
	if ( is_user_logged_in() ) {
		// Get the current activity item
		$activity = bp_get_activity_current_comment();

		// Get the comment count for the activity item
		$comment_count = bp_activity_get_comment_count( $activity->id );

		// Display the comment count
		echo 'Comment count: ' . $comment_count;
	}
}
add_action( 'bp_activity_entry_meta', 'my_custom_activity_comment_count' );

This code will display the comment count for the current activity item, but only for logged-in users. The comment count will be displayed using the bp_activity_entry_meta action hook, which is used to display the metadata for an activity item (such as the time and date it was posted, the author, etc.).

You can modify this code to display the comment count in any way you like. For example, you could wrap the comment count in a link to the activity item’s comments section, or you could style the

Share this post

You might also like...

Comment

Your email address will not be published. Required fields are marked *