How to customize programmatically comment fields in WordPress

Let’s say you want to customize your comments section, in particular the submit button text, textarea label, and the placeholder.
We will have them in this example in the German language: “Kommentar” for the textarea label, “Bitte hinterlassen Sie hier Ihre Kommentare. Danke!” for the textarea placeholder, and “Kommentar hinzufügen” for the submit button text.
Go to your functions.php file, and paste the following codes below:

For the textarea label and placeholder:

// kommentar customize code 
function wpsites_modify_comment_form_text_area($arg) {
    $arg['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x( 'Kommentar', 'noun' ) . '</label><textarea id="comment" name="comment" placeholder=" Bitte hinterlassen Sie hier Ihre Kommentare. Danke!"cols="45" rows="1" aria-required="true"></textarea></p>';
    return $arg;

add_filter('comment_form_defaults', 'wpsites_modify_comment_form_text_area');

For the submit button text:

function change_comment_form_submit_label($arg) {
  $arg['label_submit'] = 'Kommentar hinzufügen';
  return $arg;
add_filter('comment_form_defaults', 'change_comment_form_submit_label', 11);

So, that’s it. Simple.

Posted by Edgar Hovhannisyan


Your email address will not be published. Required fields are marked *