How can I move my custom comment fields above the comment field?

Currently i am using hooks comment_form_after_fields and comment_form_logged_in_after. Unfortunately due to Wordpress 4.4 changes, when a user is not logged-in the comment field is shown first and then the 'Name' and 'email' default fields. This means my custom fields are below the default fields.

I have 'comment-title' and 'rating'fields that I need above the comment field.

Is there another Hook I could use? If not should I resort to editing a comment comments.php?

  • Here's one kind of approach that might help?
    – birgire
    Mar 15 '16 at 1:17
  • @birgire thanks for that, but it only talks about the default fields. I want my custom fields to be above the comment field and available to logged-in/out users.
    – Adzay
    Mar 15 '16 at 11:54
  • You need to show your current code. Else it's guessing.
    – kaiser
    Mar 23 '16 at 1:28

Sure, you could use the comment_form_field_comment filter to inject content (extra fields or whatever) above the comment field:

function comment_form_field_comment_add_field( $field ) {
    $new_field = '<p class="comment-form-extra"><label for="extra">Extra Field</label> <input id="extra" name="extra" type="text" value="" size="30" aria-required="true" required="required"></p>';

    $field = $new_field . $field;

    return $field;
add_filter( 'comment_form_field_comment', 'comment_form_field_comment_add_field' );

You could also switch that around to put the new/extra field below the comment field:

$field = $field . $new_field;

Screenshot with twentyfourteen: http://b.ustin.co/1dvho

  • Will these fields also show when the user is logged in?
    – Adzay
    Mar 15 '16 at 11:50
  • @Adzay yes, they should, as it's a filter on the comment field which displays for those logged in and not logged in. Obviously, if you wanted to only make the field invisible to logged out users (or vice-versa), you could update the snippet to wrap the additional field in a is_user_logged_in() check. Mar 15 '16 at 17:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.