comments_number() is quite useful: It takes the result of get_comments_number() and prepares the output with some localization magic. Unfortunately, it prints the result out when it is done, it doesn’t offer an option to just return the string.

How can I get the string without printing it? I want to use it as a variable value.

2 Answers
2

Easiest way:

ob_start();
comments_number();
$data = ob_get_clean();

$data will contain the text.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *