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.
Easiest way:
$data will contain the text.
Since WordPress 4.0, you can use the function
get_comments_number_text()
. See ticket #10177.Old answer
Create a wrapper function: filter the result of
comments_number()
, store it in your wrapper, and return an empty string to the native function.return
the real string in your wrapper function.Usage: