Im using a custom filter to change the fields, but can´t figure out how to change the order of the fields in the comment form.
Desired order:
- comment field (first/top)
- name
- website
This is the code which I am currently using:
function alter_comment_form_fields($fields){
$fields['comments'] = 'Test';
$fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Your name, please' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" placeholder="John Smith" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
$fields['email'] = 'next'; //removes email field
//$fields['url'] = ''; //removes website field
return $fields;
}
add_filter('comment_form_default_fields','alter_comment_form_fields');
That’s pretty simple. You just have to take the
textarea
out of the default fields â filter'comment_form_defaults'
â and print it on the action'comment_form_top'
:There are obviously a number of ways to accomplish this. For example, to move the comment field to the bottom of the form you would use code like this:
If you wanted to rearrange all the fields:
Simple right? I figured I’d spell it out explicitly for the next noobie like me to find this page and not find the answers useful.
I liked toscho answer.
However I wanted to use a custom textarea, so it didn’t work in that case.
I used the same hooks but with separate functions:
The exact CSS to do this will depend on your theme, however, here’s one way:
The table display methods let you reorder things of arbitrary height.
More info: http://tanalin.com/en/articles/css-block-order/
the fields od comment form are in the array
$fields
in functioncomment_form()
. You can hook inside the filtercomment_form_default_fields
and reorder the array.Also you can hook inside filter
comment_form_defaults
and change the defaults; leave all data in array and change only thefield
of the array with your custom fields; include the html.the default if $fields: