Search

How to Display the Number of Post Comments in WordPress (Without Plugin)

By showcasing the total number of comments, visitors are more likely to perceive the website as active and lively, encouraging them to join the conversation. This increased level of engagement can lead to a vibrant community of users who share their thoughts, exchange ideas, and contribute valuable insights.

Some themes like Neve and Astra already show the total number of comments on the main blog page and in a single post. However, if your theme doesn’t offer this feature, worry not, even if you’re not going to install any plugin, you can still show it using a code snippet.

This tutorial will guide you through displaying the total number of comments on your WordPress website without using a plugin. And for page builder users, we will show you how to add the number to almost any element or module you desire without the need to install an additional plugin.

Displaying the Total Number of Comments on WordPress

To display the number of comments in WordPress without using a plugin from a third party, you need to use code snippet for this. This code can be placed on your theme files, on a separate file, or on your own custom plugin.

Before you start adding the snippets to your theme files, you might want to back up your site to avoid breaking your theme. Or, you can use a child theme to avoid losing your changes when you update or change your theme.

Display the Total Number of Comments Above the Content

This method will display the number of comments each post has on your main blog page and in the post itself just above the content. Start by navigating to Appearance → Theme File Editor from your WordPress dashboard and then select the functions.php file. Add the following snippet to the bottom of the file editor.

add_filter('the_content','wpp_total_comment');

function wpp_total_comment($content)
{
	$totalcomments = get_comments_number();
	$commentlink = get_comments_link();
	$content = "<p>This post has <a href='".$commentlink."'>".$totalcomments." reviews. </a></p>" . $content;
	
	return $content;

}

The above code will display the total number of comments within the sentence “this post has x reviews” while x is the total number of comments with a clickable link to the comment section of the post.

Display the Total Number of Comments for Page Builder

Sure, page builders have an option to show total comments like Divi in the Post Title module and Elementor in the Post Info element. However, if you want to have other text beside “Comments” after the number, like if we want it to be “reviews” instead, there still no option to change it tough.

With the following method, you’ll have the ability to display total comments and add any word after or before the number without installing more plugin.

Start by navigating to Appearance → Theme File Editor from your WordPress dashboard and then select the functions.php file. Add the following code snippet to the bottom of the file editor.

function wpp_totalcomment() {
    $gettotalcomments = get_comments_number();
    
    return $gettotalcomments;
}

What the code above does is create the [totalcomments] shortcode with a function to retrieve the amount of comments a post has. So, if you place the [totalcomments] in a text module on your single post template for instance, then you’ll get the total amount of the comment displayed on each post using that template.

Here is the example of how to implement the shortcode to show the total number of comments on the Elementor meta data. First, we create a single post template and add the Post Info widget to the template. Then, add a custom item to the element and type [totalcomments] to the provided field and type the noun word after like follows.

Now, publish the template and then load one of your posts using that template to see the result.

The Bottom Line

The display of comment totals serves as a social proof element, instilling confidence in visitors. When they see a substantial number of comments, they perceive the content as valuable and trustworthy, reinforcing their decision to invest time and attention in reading and participating. This tutorial shows you how to display the total number of comments on your WordPress website without using a plugin.

This page may contain affiliate links, which help support our project. Read our affiliate disclosure.
Hendri Risman

Hendri Risman

Hendri is a WordPress expert and a writer staff at WPPagebuilders. He writes solutions on how to get things fixed in WordPress a lot. Mostly without involving a plugin.
Want to save yearly expense up to $219? why not?

Leave a Comment