EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
EDIT I am trying to change the class and id of the <form>
element and well as the <input>
/Submit button field using the comment_form()
function. How ever it appears that various string values are being echoed out instead of replacing the default values (see demo link).
CODE:
<?php if ( comments_open() ) : ?>
<?php
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? ' aria-required="true"' : '' );
$fields = array(
'id_form' => 'comment-form',
'class_form' => 'form-inline',
'class_submit' => 'btn btn-default',
'author' => '<div class="form-group">
<label for="comment-author" class="sr-only">' . __( 'Author', 'magneton' ) . '</label>
<input type="text" name="author" id="comment-author" class="form-control" placeholder="' . __( 'Author (required)', 'magneton' ) . '"' . $aria_req . '>',
'email' => '<label for="comment-author-email" class="sr-only">' . __( 'E-Mail', 'magneton' ) . '</label>
<input type="email" name="email" id="comment-author-email" class="form-control" placeholder="' . __( 'E-Mail (required)', 'magneton' ) . '"' . $aria_req . '>',
'url' => '<label for="comment-author-url" class="sr-only">' . __( 'Website', 'magneton' ) . '</label>
<input type="url" name="url" id="comment-author-url" class="form-control" placeholder="' . __( 'Website'. 'magneton' ) . '">
</div>'
);
$comments_args = array(
'fields' => $fields,
'title_reply' => __( 'Leave a reply', 'magneton' ),
'comment_field' => '<textarea name="comment" id="comment" class="form-control" aria-required="true" rows="10"></textarea>',
'label_submit' => __( 'Submit Comment', 'magneton' )
);
?>
<?php comment_form( $comments_args ); ?>
<?php endif; ?>
LINK: DEMO
Share Improve this question edited May 4, 2017 at 20:25 Frederick M. Rogers asked May 4, 2017 at 17:54 Frederick M. RogersFrederick M. Rogers 1352 silver badges10 bronze badges 3 |1 Answer
Reset to default 1Those classes are being rendered inline because the id_form
, class_form
, and class_submit
parameters should be placed within the $comments_args
array (alongside title_reply
, comment_field
, etc) and not within the $fields
array. See comment_form().
Also one last question, is there any way to re-arrange the order of the fields?
Yes, the fields can be reordered. Here's an answer that shows how to accomplish reordering and customizing the comment fields. The main gotcha with reordering the comment fields is that if you want the main comment field to appear above the name/email/URL/etc fields, the comment_form_defaults
filter needs to be used to set $comment_field
to an empty string. This is because of how the parameters are set up; $comment_field
is special and not part of the $fields
array by default. This is covered in the answer linked above.
id_form
,class_form
, andclass_submit
items out of$fields
and into the$comments_args
array (alongsidetitle_reply
,comment_field
, etc). Seecomment_form()
. – Dave Romsey Commented May 4, 2017 at 20:33