One example of the comments.php is available here.

I have created comments.php file in my theme folder. In my content.php my HTML for displaying comment form looks like this:

<textarea name="name" rows="8" cols="80"></textarea>
    <div class="t-comment-section">
        <p>Full Name:</p>  <input type="text" name="Full Name">
        <p>Email:</p>  <input type="text" name="Email address">
        <p>Website:</p>  <input type="text" name="Website url">
        <a href=""><i class="fa fa-comment" aria-hidden="true"></i><span> Submit Comment </span></a>

How should I connect my comments.php to the HTML that will be used to display the comment form in my single.php or in short all the post pages that will appear?


The comment_form() function is pretty customizable, and it accepts a variety of arguments. Take a look at these sample arguments, you can modify them to fit your needs:

$fields =  array(
    'author' =>
        '<input name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .'" size="30" placeholder="'.__('Your name','text-domain').( $req ? ' (Required)' : '' ).'"/>',
    'email' =>
        '<input name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .'" size="30" placeholder="'.__('Your email','text-domain').( $req ? ' (Required)' : '' ).'"/>',
$args = array(
    'id_form'           => 'commentform',
    'class_form'        => 'comment-form',
    'id_submit'         => 'submit',
    'class_submit'      => 'submit',
    'name_submit'       => 'submit',
    'submit_button'     => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
    'title_reply'       => '',
    'title_reply_to'    => __( 'Reply to %s','text-domain' ),
    'cancel_reply_link' => __( 'Cancel comment','text-domain' ),
    'label_submit'      => __( 'Post comment','text-domain' ),
    'format'            => 'xhtml',
    'comment_field'     =>  '<textarea id="comment" name="comment" placeholder="'.__('Comment text','text-domain').'" cols="45" rows="8" aria-required="true">' .'</textarea>',
    'logged_in_as'      => '<p class="logged-in-as">' .
                              __( 'Logged in as %1$s. <a href="%2$s" title="%3$s">%4$s</a>', 'text-domain'),
                              wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ),
                              __('Log out?','text-domain'),
                              __('Click to log out.','text-domain')
                          ) . '</p>',
    'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.','text-domain' ) .'</p>',
    'fields'            => apply_filters( 'comment_form_default_fields', $fields ),

comment_form( $args );

You can add any class to the elements, or wrap them in <div> or <p>.

If you want to move the text area below the other fields, you can use the comment_form_fields filter:

function move_comment_field_to_bottom( $fields ) {
    $comment_field = $fields['comment'];
    unset( $fields['comment'] );
    $fields['comment'] = $comment_field;
    return $fields;

add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );


To include the comment form in your content.php file, save the first code in your comment.php, and then call the form in the loop this way:

if ( comments_open() || '0' != get_comments_number() ) {

This will append the comment.php to your content.

| improve this answer | |

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