Site logo

Archived topic

Displaying comments count in single posts

3 replies · Started by Peter on October 6, 2020

Viewing posts 1–4 of 4

Hello

I used the following code to display comments count on single posts:

add_filter( 'generate_post_author', 'change_author_to_comments' );
function change_author_to_comments()
{ 
  if ( is_single() ) {
	echo '| <span class="comments-links">';
                  comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
      echo '</span>'; 
  }
}

It worked find until I updated GeneratePress to 3.0.0...

(I added the above code snippet to replace author name with comments count.)

Is there a way to display comments count in posts?

My WordPress URL is https://www.thewordcracker.com/en-us/. (I removed the above code.)

Thanks.

That's strange. Your code looks fine. Though, if I may suggest, use a different hook.

That said, can you try hooking it elsewhere?

Try this code out. This should display the comment count after entry header.

add_filter( 'generate_after_entry_header', 'change_author_to_comments' );
function change_author_to_comments()
{
if ( is_single() ) {
echo '| <span class="comments-links">';
comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
echo '</span>';
}
}

Let us know how it goes.

Thanks.

Your code works fine.

Nice one. No problem. :)

This archived topic is closed to new replies.