Support » Developing with WordPress » modifying comment_form() output

  • I would like to wrap the name, email and website labels and inputs and the submit button into one div (but not the comment textarea).
    I’m sure this will involve using either comment_form_default_fields or just passing arguments to comment_form() but as a newbie to WordPress I’m not that sure of what to do.
    I want to achieve the following code:
    <p class=”comment-form-author”>…</p>
    <p class=”comment-form-email”>…</p>
    <p class=”comment-form-url”>…</p>
    <p class=”form-submit”>…</p>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    There’s no comment_form() argument to achieve what you want. You could use the ‘comment_form_fields’ filter to add a <div> in front of the first field after the textarea, and add a </div> to the last field. Or use the ‘comment_form’ filter to alter the entire content inside the <form> element. You’d need to parse through the content to locate the closing </textarea> in order to properly locate your <div>.

    The action hooks ‘comment_form_before_fields’ and ‘comment_form_after_fields’ are what you are looking for. You can print the opening and closing div respectively.

    The comment’s textarea is printed after ‘comment_form_after_fields’ executes, so it fits just right.

    You can check the code/comments in the function definition of comment_form() in wp-includes/comment-template.php lines 2360-2405 and you’ll see that the textarea gets treated differently.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘modifying comment_form() output’ is closed to new replies.