I want to display the number of comments a particular post has, so i thought i'd use comments_number, however when i use this the comment number gets printed outside of the span it's supposed to be contained within.

I tried using get_comments_number too, but that instead displays nothing at all.

The code below has been added to my functions.php amongst other code, but i just cannot get the comment number to display inside the span - it just prints at the top of the page.

$content .= '<p class="meta"><span class="date">'.$date.'</span><span class="comments">'. comments_number() .'</span></p>';

1 Answer 1


comments_number doesn't return the number of comments, it echos it out.

As the codex clearly states:

Use get_comments_number() to retrieve the value.

  • Seems there was an issue with how i was initially using get_comments_number - but yes, it works like a charm. Commented Apr 10, 2013 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.