It seems that WordPress handles the comment field separately than the other fields. If you look at comment_form()
in wp-includes/comment-template.php
, you can see this.
It’s possible to set $defaults['comment_field']
to false in alpha_comments_defaults()
then add the comment field markup to $fields['comment_field']
in alpha_comments_fields()
in the desired order, but this could cause trouble with plugins.
I’ve moved things around and added code to handle the field ordering that you requested.
function alpha_comments_defaults( $defaults ) {
$defaults['id_form'] = '';
$defaults['id_submit'] = '';
$defaults['comment_field'] = '<p class="comment-form-comment"><label>' . _x( 'Comment', 'noun' ) . '</label>' .
'<textarea name="comment" cols="45" rows="8" aria-required="true"></textarea></p>';
return $defaults;
}
add_filter('comment_form_defaults', 'alpha_comments_defaults');
function alpha_comments_fields( $fields ) {
$commenter= wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : ' ' );
$fields = array(
'author' =>
'<p class="comment-form-author"><label>' . __( 'Name', 'domainreference' ) . ( $req ? '<span class="required">*</span>' : '' ) . '</label> ' .
'<input name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" ' . $aria_req . ' /></p>',
'email' =>
'<p class="comment-form-email"><label>' . __( 'Email', 'domainreference' ) . ( $req ? '<span class="required">*</span>' : '' ) . '</label> ' .
'<input name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" ' . $aria_req . ' /></p>',
'url' => '',
);
return $fields;
}
add_filter('comment_form_default_fields', 'alpha_comments_fields');
// Reorder comment fields.
// http://wordpress.stackexchange.com/a/218324/2807
function alpha_move_comment_field( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'alpha_move_comment_field' );