Change comment fields order


Hi thierry,

I'm newbie wp developer. I wanted the line (field Name, Email, Website) is above (field Comment), not as now. How do I change it safely?

Thanks,


Hey Rico, welcome to the forum 🙂

The comment fields order is handle on the WP Core side but you may use the comment_form_fields filter to re-order them. Here is the code snippet I would suggest.

add_filter( 'comment_form_fields', 'example_order_comment_form_fields' );

function example_order_comment_form_fields( $fields ) {

  // Move comment field last.
 $fields['comment'] = array_shift( $fields );

  return $fields;

}

A less "elegant" way but faster would be as follow:

add_filter( 'comment_form_fields', 'example_order_comment_form_fields' );

function example_order_comment_form_fields( $fields ) {

 $comment = $fields['comment'];

  unset( $fields['comment'] );

  $fields['comment'] = $comment;

  return $fields;

}

Note that both examples do exactly the same, the first one is a bit shorter and more elegant while the second one is faster PHP wise.

Hope that helps,


Yes! it worked perfectly as I wanted.

Thanks!

Write a reply

Login or register to write a reply, it's free!