The comment_form_field_{$name} WordPress PHP filter allows you to modify a comment form field for display.
Usage
add_filter( 'comment_form_field_comment', 'your_custom_function' );
function your_custom_function( $field ) {
// your custom code here
return $field;
}
Parameters
$field(string) – The HTML-formatted output of the comment form field.
More information
See WordPress Developer Resources: comment_form_field_{$name}
Examples
Change the Comment Field Placeholder Text
Modify the comment field placeholder text on the comment form.
add_filter( 'comment_form_field_comment', 'change_comment_field_placeholder' );
function change_comment_field_placeholder( $field ) {
$field = str_replace( 'placeholder="Comment"', 'placeholder="Share your thoughts..."', $field );
return $field;
}
Add a Custom Class to the Author Field
Add a custom CSS class to the author input field in the comment form.
add_filter( 'comment_form_field_author', 'add_custom_class_author_field' );
function add_custom_class_author_field( $field ) {
$field = str_replace( 'class="', 'class="your-custom-class ', $field );
return $field;
}
Remove URL Field from Comment Form
Remove the URL input field from the comment form.
add_filter( 'comment_form_field_url', 'remove_url_field' );
function remove_url_field( $field ) {
return '';
}
Add a Placeholder to the Email Field
Add a placeholder to the email input field in the comment form.
add_filter( 'comment_form_field_email', 'add_placeholder_email_field' );
function add_placeholder_email_field( $field ) {
$field = str_replace( 'type="email"', 'type="email" placeholder="Your email address"', $field );
return $field;
}
Wrap the Comment Form Fields in a Div
Wrap the comment form fields in a div with a custom class.
add_filter( 'comment_form_field_comment', 'wrap_comment_form_fields' );
function wrap_comment_form_fields( $field ) {
$field = '<div class="your-custom-wrapper">' . $field . '</div>';
return $field;
}