Archived topic
Comment count in meta of single post
3 replies · Started by Dong on October 7, 2020
Hi guys,
It seems the latest update breaks the comment counts in the meta of a single post. And all the existing tricks don't work -- they only work for the meta of the archive. Basically, I'd like to have the meta in this format:
[Date] • Writer • Comment count (the first two are already there like in the post below.)
https://dongknows.com/get-your-home-wired-with-network-cables/
Better yet, if possible, I'd like the meta to be:
[Date] • Writer • [Number of minutes] to read • Comment count
How can I bring them back? Thanks.
-Dong.
Hi there,
Can you share the current functions you were using that are no longer working?
I used the code below but it has two problems:
1. The comment count only appears on the archive page, not in a single post.
2. On the archive page, it shows in two places, below the Headline and also below the excerpt. When I turn off "Display comment count" using the Layout Customization then it disappears in both.
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date',
'comments-link',
);
} );
add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
if ( '' === $item ) {
return '';
}
if ( 'comments-link' === $item ) {
return ' • ';
}
if ( 'date' === $item ) {
return ' • ';
}
return $output;
}, 50, 2 );
Add this as well:
add_action( 'wp', function() {
if ( is_single() ) {
add_filter( 'generate_show_comments', '__return_true' );
}
} );
add_filter( 'generate_footer_entry_meta_items', function( $items ) {
return array_diff( $items, array( 'comments-link' ) );
} );