[Resolved] Displaying comments count in single posts

Home Forums Support [Resolved] Displaying comments count in single posts

Home Forums Support Displaying comments count in single posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1475508
    Peter

    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.

    #1475540
    Elvin
    Staff
    Customer Support

    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.

    #1475567
    Peter

    Thanks.

    Your code works fine.

    #1475574
    Elvin
    Staff
    Customer Support

    Nice one. No problem. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.