11 Jan 2017

Modifying the comments form

Take a look in the themes comments.php file and you will see a line where the comments area is called in using:


<?php comment_form(); ?>

In some cases I found it was contained within a conditional like this:


if ( comments_open() ) comment_form();

You can replace it with the following code, injecting in any modifications to the fields as you need:

if ( comments_open() ) { ?>

<?php $comment_args = array( 'title_reply'=>'Leave a reply',

'fields' => apply_filters( 'comment_form_default_fields', array(

'author' =>
'<div class="row">
<div class="large-4 columns comment-form-author">' .
'<input id="author"
name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' placeholder="Name*" />
</div>',

'email' =>
'<div class="large-4 columns comment-form-email">' .
'<input id="email" name="email" type="text"
value="' . esc_attr( $commenter['comment_author_email'] ) .
'" size="30"' . $aria_req . ' placeholder="Email*" />
</div>',

'url' =>
'<div
class="large-4 columns comment-form-url">' .
'<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
'" size="30"
placeholder="Website" />
</div>
</div>', )
),

'comment_field' => '<div>' .

'<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" placeholder="Comment*"
></textarea>' .

'</div>',

'comment_notes_after' => '',

);

comment_form($comment_args); ?>


<?php } ?>