Using WordPress ‘comment_form_field_comment’ PHP filter

The comment_form_field_comment WordPress PHP filter modifies the content of the comment textarea field for display.

Usage

add_filter('comment_form_field_comment', 'your_custom_function');
function your_custom_function($args_comment_field) {
  // your custom code here

  return $args_comment_field;
}

Parameters

  • $args_comment_field (string) – The content of the comment textarea field.

More information

See WordPress Developer Resources: comment_form_field_comment

Examples

Change the placeholder text

Update the placeholder text for the comment textarea field.

add_filter('comment_form_field_comment', 'change_placeholder_text');
function change_placeholder_text($args_comment_field) {
  $args_comment_field = str_replace('Leave a Reply', 'Share your thoughts', $args_comment_field);
  return $args_comment_field;
}

Add a custom class to the textarea

Add a custom CSS class to the comment textarea field.

add_filter('comment_form_field_comment', 'add_custom_class');
function add_custom_class($args_comment_field) {
  $args_comment_field = str_replace('<textarea', '<textarea class="custom-class"', $args_comment_field);
  return $args_comment_field;
}