How to add a div on comment fields / edited

The comment_form() isn’t quite correct with your arguments being loaded in.

You need to pass in 'fields' => apply_filters( 'comment_form_default_fields', $fields ), into a new argument. Attached is an example of what you would need to update.

Fields you want to have filled out

$fields =  array(
  'author' =>
    '<div class="comment-form-author"><label for="author">' . __( 'Name', 'domainreference' ) . '</label> ' .
    ( $req ? '<span class="required">*</span>' : '' ) .
    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
    '" size="30"' . $aria_req . ' /></div>',
  'email' =>
    '<div class="comment-form-email"><label for="email">' . __( 'Email', 'domainreference' ) . '</label> ' .
    ( $req ? '<span class="required">*</span>' : '' ) .
    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) .
    '" size="30"' . $aria_req . ' /></div>',

  'url' =>
    '<div class="comment-form-url"><label for="url">' . __( 'Website', 'domainreference' ) . '</label>' .
    '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
    '" size="30" /></div>',
);

Comment Form Arguments

$comments_args = array(
    // change the title of send button 
    'label_submit'=>'Send',
    // change the title of the reply section
    'title_reply'=>'Write a Reply or Comment',
    // remove "Text or HTML to be displayed after the set of comment fields"
    'comment_notes_after' => '',
    // redefine your own textarea (the comment body)
    'comment_field' => '<div class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></div>',
    'fields' => apply_filters( 'comment_form_default_fields', $fields ),
);

comment_form($comments_args);

The only item of note is the 'fields' => apply_filters( 'comment_form_default_fields', $fields in the last line of the $comment_args. This will allow you to pass in update form fields.

Leave a Comment