WordPress comment_form() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_form() prints the complete comment form. It includes the name, email, website, and comment fields, a submit button, and hidden fields.

It prints the form. Put it at the end of comments.php, after the list of comments. You can change the text and the fields with arguments.

Syntax

Call it with no arguments for the default form, or pass an array to change it.

WordPress
comment_form();
comment_form( array( 'title_reply' => 'Join the talk' ) );
comment_form( $args, $post_id );
CallWhat it does
comment_form()Prints the default comment form.
comment_form( array( 'title_reply' => 'Join the talk' ) )Prints the form with a new heading.
comment_form( $args, 42 )Prints the form for the post with ID 42.

Common keys in $args are title_reply, label_submit, comment_field, fields, and class_submit.

Full declaration
WordPress
comment_form( array $args = array(), int|WP_Post|null $post = null ): void

Parameters

ParameterDescription
$argsOptional. An array that changes the form. Keys include title_reply, label_submit, comment_field, fields, class_form, class_submit, and comment_notes_before.
$postOptional. A post ID or WP_Post object. Default is the current post.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the whole form.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Default form

Print the standard form at the end of comments.php.

WordPress
<?php
if ( comments_open() ) {
  comment_form();
}
?>

How It Works

  1. comments_open() checks that comments are allowed.
  2. comment_form() prints the form with default text.
  3. The form posts to wp-comments-post.php.

Example 2 — Change the text

Change the heading and the button text.

WordPress
<?php
comment_form( array(
  'title_reply'  => 'Join the discussion',
  'label_submit' => 'Send comment',
) );
?>

How It Works

  1. title_reply sets the heading.
  2. label_submit sets the text on the button.
  3. All other parts keep their default values.

Example 3 — Remove the website field

Use a filter to remove the website field from the form.

WordPress
add_filter( 'comment_form_default_fields', function ( $fields ) {
  unset( $fields['url'] );
  return $fields;
} );

How It Works

  1. The filter gives you the array of default fields.
  2. unset( $fields['url'] ) removes the website field.
  3. Put the code in functions.php. comment_form() uses the new list.

Frequently Asked Questions

It prints the full comment form, including the fields, the submit button, and the hidden fields.
At the end of comments.php, after the list of comments.
Comments may be closed for the post, or your theme does not load comments.php.
Pass 'label_submit' in the $args array.
No. comment_form() prints the hidden fields for you.

Next: comment_form_title()

Print the form heading, or a Reply to text when replying to a comment.

comment_form_title() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful