Site logo

[Resolved] Comment count not showing in single posts meta

Home Forums Support [Resolved] Comment count not showing in single posts meta

Home Forums Support Comment count not showing in single posts meta

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1560266
    Benjamin

    Hi,

    I’m trying to get the comments count to show alongside the author name and updated date in single posts but it doesn’t seem to work.

    As you can see, the comments count just doesn’t appear:
    https://frenchtogether.com/french-words-in-english/

    Here is the code I have:

    add_filter( 'generate_post_author_output', function( $output ) {
        if ( ! is_singular() ) {
            return $output;
        }
    
        return sprintf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() ),
                get_avatar( get_the_author_meta( 'ID' ) )
            )
        );
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
    		'comments-link',
    		'date',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function() {
        return array(
            'categories',
        );
    } );

    And here is the CSS I have:

    .byline img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
        position: relative;
        vertical-align: middle;
        margin: 0 10px 0 0;
    }
    
    .single-post .entry-content img {
    	  box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    }
    
    .entry-meta a{
    	margin-right: 10px;
    }
    
    .single .comments-link {
        display: inline-block;
    }

    Any idea what’s wrong?

    Thanks

    #1561276
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try adding this:

    add_action( 'wp', function() {
        if ( is_single() ) {
            add_filter( 'generate_show_comments', '__return_true' );
        }
    } );

    Let me know 🙂

    #1563305
    Benjamin

    Thanks, that worked 🙂

    #1564207
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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