Show the number of comments per post in WordPress

A WordPress blog post can have no, one or multiple comments associated with it.

To display the number of comments one post has, include this within the post loop, for example in content.php:

<?php $totalcomments = get_comments_number(); echo $totalcomments; ?>

This will create a variable name totalcomment and it will store the number of comments for that specific blog post. Then, you can display that number wherever you want.

In my specific case, I wanted to add schema.org markup and I created this code to include the number of comments:

<meta itemprop="interactionCount" content="UserComments:<?php $totalcomments = get_comments_number(); echo $totalcomments; ?>">

 

Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.

 

3 thoughts on “Show the number of comments per post in WordPress

Leave a Reply

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