Reorder and add Placeholders for Comment Form Fields

<?php
/**
 * Customize comment form
 *
 * @param array $fields Comment form fields.
 */
function wd_customize_comment_form_fields( $fields ) {

	// get value of fields and save as variable
	$author = $fields['author'];
	$email = $fields['email'];
	$comment = $fields['comment'];
	$url = $fields['url'];
	
     // unset other fields to allow reordering
     unset( $fields['url'] );
     unset( $fields['comment'] );
     unset( $fields['author'] );
     unset( $fields['email'] );

     // set fields in proper order with placeholder
     $fields['author'] = $author;
	 $fields['email'] = $email;
	 $fields['comment'] = $comment;
	$fields['url'] = $url;
	
	return $fields;
}
add_filter( 'comment_form_fields', 'wd_customize_comment_form_fields' );

This snippet includes adding placeholder text

<?php
/**
 * Customize comment form
 *
 * @param array $fields Comment form fields.
 */
function wd_customize_comment_form_fields( $fields ) {

     // remove URL field
     unset( $fields['url'] );

     // unset other fields to allow reordering
     unset( $fields['comment'] );
     unset( $fields['author'] );
     unset( $fields['email'] );

     // create placeholder variables
     $comment_placeholder = __( 'Comment', 'slug' );
     $author_placeholder = __( 'Name', 'slug' );
     $email_placeholder = __( 'Email', 'slug' );

     // set fields in proper order with placeholder
     $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . $author_placeholder . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" placeholder="' . $author_placeholder . '" value="' . esc_attr( $commenter['comment_author'] ) . '" size="20"' . $aria_req . ' /></p>';

     $fields['email'] = '<p class="comment-form-email"><label for="email">' . $email_placeholder . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" placeholder="' . $email_placeholder . '" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';

     $fields['comment'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" placeholder="' . $comment_placeholder . '" aria-required="true"></textarea></p>';

	return $fields;
}
add_filter( 'comment_form_fields', 'wd_customize_comment_form_fields' );

About Matt Whiteley

Matt has been building bespoke WordPress websites for over 10 years specializing in the Genesis Framework. He integrates Advanced Custom Fields heavily in all builds, especially with the new Gutenberg Block Editor, allowing clients to easily modify all aspects of the their website with ease.

He works with a wide variety of small businesses and agencies across the country providing development services as well as hosting and maintenance. When he isn't coding he enjoys spending time with his wife and two children, golfing and playing poker.