get_comments_number

Home » Functions » get_comments_number

Function Name: get_comments_number

If you have a WordPress blog, you must be aware of the importance of allowing users to comment on your posts. The get_comments_number function in WordPress is used to retrieve the number of comments made on a particular post or page.

This function returns the total number of comments on a post or page. The function can be used in the loop, in the sidebar, or anywhere else on your site where you want to display the number of comments made on a post or page.

Example usage code:

/* Retrieve the number of comments for the current post */
$comments_number = get_comments_number();
echo 'This post has ' . $comments_number . ' comments.';

In the above example, we’re using the get_comments_number function to retrieve the number of comments on the current post. We then use a simple echo statement to display the number of comments.

Overall, the get_comments_number function is a simple yet useful function that helps WordPress users keep track of the number of comments on their posts and pages.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.