If you scroll further down the comment-template.php file, you’ll notice that the next available filter you can use is comment_form_defaults
. With this filter you can change the default comment form configuration.
add_filter( 'comment_form_defaults', 'filter_comment_form_defaults' );
function filter_comment_form_defaults( $defaults ) {
$defaults['comment_field'] = sprintf(
'<p class="comment-form-comment">%s %s</p>',
sprintf(
'<label for="comment">%s</label>',
_x( 'Please leave a comment...', 'Comment field label', 'textdomain' )
),
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>'
);
return $defaults;
}
But your (parent) theme might also make some modifications to the fields so the default values might get overwritten. So just keep scrolling down and you’ll eventually see comment_form_fields
filter. This filters the comment form fields, including the textarea.
add_filter( 'comment_form_fields', 'filter_comment_form_fields' );
function filter_comment_form_fields( $fields ) {
$fields['comment'] = sprintf(
'<p class="comment-form-comment">%s %s</p>',
sprintf(
'<label for="comment">%s</label>',
_x( 'Please leave a comment...', 'Comment field label', 'textdomain' )
),
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>'
);
return $fields;
}
If you only want to target the comment field, then below the previous filter, you can see in a foreach loop the comment_form_field_comment
filter.
add_filter( 'comment_form_field_comment', 'filter_comment_form_field_comment' );
function filter_comment_form_field_comment( $field ) {
return sprintf(
'<p class="comment-form-comment">%s %s</p>',
sprintf(
'<label for="comment">%s</label>',
_x( 'Please leave a comment...', 'Comment field label', 'textdomain' )
),
'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>'
);
}
Please refer to the WP code reference (links) for more details about the filters.