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';


1 Answer 1


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.

  • Works like a charm just want to confirm ? if this exclude the trackback and pings ?
    – Cid Ubaid
    Jun 2, 2013 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, 2013 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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