0

I'm trying to add author, email fields to comment form but the comment form does not change. It is always showing a default template with only the comment field and submit button.

Could this be a caching issue or it is reading the comment form template from another directory?

I am using this code in my page template :

$comments_args = array(
  'label_submit' => __('コメント送信'),
  'title_reply' => __('コメント登録'),
  'fields' => apply_filters('comment_form_default_fields', array(
    'author' =>
    '<p class="comment-form-author">'.
    '<input id="author" class="blog-form-input" placeholder="Your Name* " name="author" type="text" value="'.esc_attr($commenter['comment_author']).
    '" size="30"'.$aria_req.
    ' /></p>',
    'email' =>
    '<p class="comment-form-email">'.
    '<input id="email" class="blog-form-input" placeholder="Your Email Address* " name="email" type="text" value="'.esc_attr($commenter['comment_author_email']).
    '" size="30"'.$aria_req.
    ' /></p>',
  )),
  'comment_notes_after' => '',
  'comment_field' => '<p class="comment-form-comment"><label for="comment">'._x('Comment', 'noun').
  '</label><br /><textarea id="comment" name="comment" aria-required="true" cols="75"></textarea></p>',
);
comment_form($comments_args);
  • why are you using apply_filters? you should add a filter – inarilo Dec 26 '17 at 20:23
0

You can put this code in your current theme function.php file More Info

<?php

    add_action( 'comment_form_logged_in_after', 'additional_fields' );
    add_action( 'comment_form_after_fields', 'additional_fields' );

    function additional_fields () {
      echo '<p class="comment-form-title">'.
      '<label for="title">' . __( 'Comment Title' ) . '</label>'.
      '<input id="title" name="title" type="text" size="30"  tabindex="5" /></p>';
    }
?>

EDIT:

$comments_args = array(
       'comment_notes_after' => '<p><label for="comment">' . _x( 'NEW', 'noun' ) .
    '</label><input id="new" name="new" aria-required="true">' .
    '</input></p>',
    );

    comment_form($comments_args);

Check more Argument list

enter image description here

  • Can i edit comment form from my template page using comment_form($custom_fields); instead of inserting them directly into functions.php ? – Nick W Dec 26 '17 at 12:16
  • Using it as comment_form($comments_args); does not work. I still see the comment form with comment field and submit button – Nick W Dec 26 '17 at 12:27
  • custom filed add into this 'comment_notes_after'. – Jignesh Patel Dec 26 '17 at 12:30
  • That did not work – Nick W Dec 26 '17 at 12:42
  • please check my screen shot it's work for me – Jignesh Patel Dec 26 '17 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.