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 a custom function to pre fill the comment text area with the number of comment count but getting an error header already sent can any body guide me here's the code I am using

  add_action('pre_comment_on_post', 'dump_comment');
   function dump_comment($post_id, $author=null, $email=null) {
   $comcnt = $cmntcount = comments_number( '#0', '#1', '#%' );
   $comment = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
   if (!$comment) {
   $_POST['comment'] = 'Design' . '$comcnt';

share|improve this question
up vote 0 down vote accepted

I think the reason for your header already sent error is that you are using


that will echo the value.

Try instead

get_comments_number( $post_id );

to return it.

The Codex info on this function says that it returns the total number of comments, trackbacks, and pingbacks for the post.

share|improve this answer
Works like a charm just want to confirm ? if this exclude the trackback and pings ? – Cid Ubaid Jun 2 '13 at 9:39
ok great ;-) ps: the Codex says that this will give you the total number of comments, Trackbacks, and Pingbacks for a post – birgire Jun 2 '13 at 9:45

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.