WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using WooTheme's Canvas theme and would like to "hardcode" in the [post_comments] shortcode into my theme. [post_comments] displays a comment link with comment count (ie Comments 10) in my post. Right now I am inserting the [post_comments] shortcode into my theme's meta "Meta Manager"; however, this is not ideal for me as I have limited control over the placement of where the this shows up in my post. What type of function or such should I be looking for to do this within my .php files?

Thank you

share|improve this question

migrated from stackoverflow.com Jul 1 '11 at 2:16

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

Check out do_shortcode(): http://codex.wordpress.org/Function_Reference/do_shortcode

do_shortcode('[shortcode option1="value1" option2="value2"]');

So your example would be:


What might be easier is to tap into the underlying comment functions:


  This post currently has
  <?php comments_number( 'no responses', 'one response', '% responses' ); ?>.

You can also use get_comments_number which returns the value rather than printing it to the screen.

This function however needs to be in the Loop for it to work, however I have a feeling it is.

share|improve this answer
Thanks for the reply.But this didn't seem to work. do_shortcode('[post_comments]'); I placed this in my content-post.php file – Brian Housman Jun 30 '11 at 17:38
Where is that shortcode defined, is it in the Canvas theme? – danielrsmith Jun 30 '11 at 21:14
Thanks! get_comments_number() is a great solution! I'm just going to add "Comments" text and wrap the number in "()". – Brian Housman Jun 30 '11 at 22:19
Yes, [post_comments] is defined within theme-shortcodes.php – Brian Housman Jun 30 '11 at 22:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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