More

    How to Display the Total Number of Comments in WordPress

    Do you want to display the total number of comments on your WordPress site?

    Comments allow users to participate and engage with the content on your website. By showing off the total comment count, you can encourage more users to join the conversation.

    In this article, we will show you how to easily display the total number of comments in WordPress, with or without a plugin.

    Display WordPress Comment Count using a Plugin

    This method is easier and it is recommended for all users. Instead of writing code, you’ll be using a plugin to display comment count in WordPress.

    First, you need to install and activate the Simple Blog Stats plugin. You may read our step by step guide on how to install a WordPress plugin for detailed instructions.

    Upon activation, go to Settings » Simple Blog Stats page to configure plugin settings.

    On this page, you’ll see all the shortcodes that you can use to show different stats like the total number of comments, registered users, number of posts, categories, page count, and more.

    You need to copy the shortcode [sbs_approved] to display the total number of approved comments on your WordPress site.

    If you want to display it in a post or page, then simply create a new post or edit an existing one.

    On the post edit screen, you need to add the shortcode block in the WordPress content editor.

    You can do this by clicking on the Add block (+) icon and then search for the shortcode block. Once you find it, you need to click on it to add the shortcode block to the editor.

    Next, you need to paste the shortcode [sbs_approved] inside the block settings.

    You can add any text you want to display before or after the shortcode.

    Alternatively, you can also use the shortcode inside a paragraph block. Simply copy and paste the shortcode where you want to display the comment count.

    Using the paragraph block will also allow you to use the text styling option available in the WordPress block editor.

    Once you are done, click on the publish or update button to save your changes. You can now visit your website to see your changes in action.

    Displaying total comment count in a sidebar widget

    You can also use the same shortcode inside a WordPress widget and display it in your blog’s sidebar.

    Simply head over to the Appearance » Widgets page and add a ‘Text’ widget to the sidebar.

    Next, go ahead and paste your shortcode inside the ‘Text’ widget.

    Don’t forget to click on the ‘Save’ button to store your widget settings.

    You can now visit your website to see the widget in action.

    Display WordPress Comment Count (without a plugin)

    If you don’t want to use a plugin, then you can use display the total comment count manually.

    This method requires you to add a code snippet to your website. If you haven’t done this before, then please check out our guide on how to copy and paste code snippets in WordPress.

    Before you do anything, you should make a full backup of your website. This will help you to restore your site in case you break anything while editing the theme files.

    Now you need to add the following code to your theme’s functions.php file or a site-specific plugin:

    function wpb_comment_count() { 
    $comments_count = wp_count_comments();
    $message =  'There are '.  $comments_count->approved . ' comments posted by our users.';
    
    return $message; 
    } 
    
    add_shortcode('wpb_total_comments','wpb_comment_count'); 
    
    

    This code creates a function that outputs the total number of approved WordPress comments on your site. It also creates a shortcode to display it.

    You can now use the shortcode [wpb_total_comments] in your posts, pages, or a text widget to display the total number of comments on your website.

    This is how it looked on our demo site:

    We hope this article helped you display the total number of comments on your WordPress site. You may also want to check out our guide on how to prevent comment spam in WordPress and the best WordPress plugins for every website.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Display the Total Number of Comments in WordPress appeared first on Techevangelistseo.

    Recent Articles

    5 Things to Know About the macOS 10.15.2 Update in December

    5 Things to Know About the macOS 10.15.2 Update in December is a post by Josh Smith from Gotta Be Mobile. Apple is working on...

    5 Best WordPress Business Directory Plugins

    Are you looking for the best WordPress business directory plugins? A business directory helps users discover service providers in a particular niche or category. At...

    René Auberjonois, Odo from ‘Star Trek: Deep Space Nine’, has died

    Veteran actor and singer René Auberjonois has died of metastatic lung cancer at his Los Angeles home on Dec. 8. Auberjonois' son Rèmy-Luc confirmed...

    Pokémon Sword and Shield Berries, Berries, and more Berries!

    A common feature in Pokémon games, Berries serve many purposes and Pokémon Sword and Shield is no different. Within battle, your Pokémon can eat...

    This week’s top stories: Completely wireless iPhone in 2021, App Store awards, Mac Pro, more

    In this week’s top stories: Ming-Chi Kuo details the 2020 and 2021 iPhones, Apple reveals its 2019 App Store awards, Peloton launches an Apple Watch...

    Latest Stories

    Stay on op - Ge the daily news in your inbox