Customizing the WordPress Comment Form

September 15, 2022

Here are a few tutorials in customizing the WordPress Comment Form.

default wordpress comment form
This is the default comment form from the Twenty Twenty One theme

Change the WordPress Comment Form Title

By default, the comment form’s title is Leave a Comment, to change it, first, check your current theme if it has a comment.php file, and look for this part.

Twenty Twenty One theme

Change ‘Leave a Comment’ to the title you want.

If it doesn’t have that file, add this in your theme’s functions.php.

add_filter('comment_form_defaults', 'set_my_comment_title', 20);
function set_my_comment_title( $defaults ){
 $defaults['title_reply'] = __('CUSTOM NAME', 'customizr-child');
 return $defaults;
}

Change CUSTOM NAME to the title you want.


Move the comment field to the bottom of the form

function move_comment_field_to_the_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
 
add_filter( 'comment_form_fields', 'move_comment_field_to_the_bottom');

Use Placeholder Instead of Labels in Your WordPress Comment Form

// Placeholder Comments
function btg_comment_textarea_placeholder( $args ) {
	$args['comment_field']        = str_replace( 'textarea', 'textarea placeholder="Comment"', $args['comment_field'] );
	return $args;
}
add_filter( 'comment_form_defaults', 'btg_comment_textarea_placeholder' );

/**
 * Comment Form Fields Placeholder
 *
 */
function btg2_comment_form_fields( $fields ) {
	foreach( $fields as &$field ) {
		$field = str_replace( 'id="author"', 'id="author" placeholder="name*"', $field );
		$field = str_replace( 'id="email"', 'id="email" placeholder="email*"', $field );
		$field = str_replace( 'id="url"', 'id="url" placeholder="website"', $field );
	}
	return $fields;
}
add_filter( 'comment_form_default_fields', 'btg2_comment_form_fields' );

Then add this to your css file

.comment-respond label {
	display: none;
}

Style the WordPress Comment Form

https://www.wpbeginner.com/wp-themes/how-to-style-wordpress-comment-form/

Get In Touch

Email: [email protected]


CAPTCHA image

This helps us prevent spam, thank you.



Categories