The comment_form()
function is pretty customizable, and it accepts a variety of arguments. Take a look at these sample arguments, you can modify them to fit your needs:
$fields = array(
'author' =>
'<input name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .'" size="30" placeholder="'.__('Your name','text-domain').( $req ? ' (Required)' : '' ).'"/>',
'email' =>
'<input name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .'" size="30" placeholder="'.__('Your email','text-domain').( $req ? ' (Required)' : '' ).'"/>',
);
$args = array(
'id_form' => 'commentform',
'class_form' => 'comment-form',
'id_submit' => 'submit',
'class_submit' => 'submit',
'name_submit' => 'submit',
'submit_button' => '<input name="%1$s" type="submit" id="https://wordpress.stackexchange.com/questions/279525/%2$s" class="%3$s" value="%4$s" />',
'title_reply' => '',
'title_reply_to' => __( 'Reply to %s','text-domain' ),
'cancel_reply_link' => __( 'Cancel comment','text-domain' ),
'label_submit' => __( 'Post comment','text-domain' ),
'format' => 'xhtml',
'comment_field' => '<textarea id="comment" name="comment" placeholder="'.__('Comment text','text-domain').'" cols="45" rows="8" aria-required="true">' .'</textarea>',
'logged_in_as' => '<p class="logged-in-as">' .
sprintf(
__( 'Logged in as %1$s. <a href="https://wordpress.stackexchange.com/questions/279525/%2$s" title="%3$s">%4$s</a>', 'text-domain'),
$user_identity,
wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ),
__('Log out?','text-domain'),
__('Click to log out.','text-domain')
) . '</p>',
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.','text-domain' ) .'</p>',
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
);
comment_form( $args );
You can add any class to the elements, or wrap them in <div>
or <p>
.
If you want to move the text area below the other fields, you can use the comment_form_fields
filter:
function move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
UPDATE
To include the comment form in your content.php
file, save the first code in your comment.php
, and then call the form in the loop this way:
if ( comments_open() || '0' != get_comments_number() ) {
comments_template();
}
This will append the comment.php
to your content.