Skip to content

Instantly share code, notes, and snippets.

@mdjwel
Created May 13, 2018 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdjwel/7d8bfcfb09ab54de61ea4698e4b81ab2 to your computer and use it in GitHub Desktop.
Save mdjwel/7d8bfcfb09ab54de61ea4698e4b81ab2 to your computer and use it in GitHub Desktop.
Get the post comment count text based the comments have in a WordPress post loop.
<?php
// Get comment count text
function prefix_comment_count($post_id) {
$comments_number = get_comments_number($post_id);
if($comments_number==0) {
$comment_text = esc_html__('No comment', 'chaoz');
}elseif($comments_number == 1) {
$comment_text = esc_html__('One comment', 'chaoz');
}elseif($comments_number > 1) {
$comment_text = $comments_number.esc_html__(' Comments', 'chaoz');
}
echo esc_html($comment_text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment