Do you want to display the total number of WordPress comments on your entire site? Use the following code to get the total number of comments, and then display it in your theme. This only gets comments with “Approved” status.
<?php // Get total number of approved comments $count_comments = wp_count_comments(); $total_comments = $count_comments->approved; echo $total_comments . ' comments. '; ?>
The $total_comments
variable will just return the number. You can change the word “comments” to say whatever you want.
I’d love to see how you use this. Please share in the comments.
Reference wp_count_comments() in the WordPress Codex.
We Recommend
https://kinsta.com › wordpress-hosting
Fast and secure infrastructure, worldwide CDN, edge caching, 35 data centers, and enterprise-level features included in all plans. Free site migrations.
https://gravityforms.com › features
Create custom web forms to capture leads, collect payments, automate your workflows, and build your business online. All without ever leaving WordPress.
Leave a Comment