Looking to replace static string text in this function with dynamic text from a var.

Current model:

  comments_number( 'no responses', '1 response', '% responses' );

Ideal Outcome (code guess):

  comments_number( '$no_responce_text', '1'.$responce_text, '%'.$responce_text );

I am sure this is an easy php question but stumped here.

Any help would be nice.


1 Answer 1


This should do it:

   sprintf('1 %s', $responce_text), 
   sprintf('%% %s', $responce_text)

Use get_comments_number if you want it properly localized.

  • There is one issue is with the last part, it is only outputting 2s (2 being a number greater than 1). Any thoughts on how to output the text with it? Does it have to do with the two %?
    – estern23
    Sep 18, 2011 at 13:40
  • yes, the first %s needed to be escaped, fixed it. Sep 18, 2011 at 13:41

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.