Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to customize the HTML output of the comment form. I've been reading

I've been reading how to alter some variables of the comment_form(). The previous link provides a rather good guide to play with that function.

But I'm still unable to change the HTML output of the form. And I would like to wrap some fields inside a container.

With older wordpress versions this could be changed at will in the comments.php function, but doing it that way will break nested comments, so it is not an option.

Is it possible at all to change this html output?

Thanks,

Upon request, a bit more of inormation :) The default html output of comment_form() is:

<p class="comment-form-author"><label for="author">Name</label> <span class="required">*</span><input id="author" name="author" type="text" value="" size="30" aria-required='true' /></p>
<p class="comment-form-email"><label for="email">Email</label> <span class="required">*</span><input id="email" name="email" type="text" value="" size="30" aria-required='true' /></p>
<p class="comment-form-url"><label for="url">Website</label><input id="url" name="url" type="text" value="" size="30" /></p>

I would like to wrap all three paragraphs inside an html element (ie. DIV).

share|improve this question
1  
We need considerably more information: specifically, what exactly you want to change in the comment reply form markup. –  Chip Bennett May 29 '12 at 20:06
1  
Thanks, Chip, I've added info about what I am exactly looking for :) –  versvs May 30 '12 at 9:30

1 Answer 1

up vote 1 down vote accepted

Upon request, a bit more of inormation :) The default html output of comment_form() is:

<p class="comment-form-author"><label for="author">Name</label> <span class="required">*</span><input id="author" name="author" type="text" value="" size="30" aria-required='true' /></p>
<p class="comment-form-email"><label for="email">Email</label> <span class="required">*</span><input id="email" name="email" type="text" value="" size="30" aria-required='true' /></p>
 <p class="comment-form-url"><label for="url">Website</label><input id="url" name="url" type="text" value="" size="30" /></p> I would like to wrap all three paragraphs inside an html element (ie. DIV).

As a matter of fact, this is quite easy! You just need to know the right hooks to use.

The comment_form() function includes, among several other action hooks, two that will suit your needs perfectly: comment_form_before_fields and comment_form_after_fields. You can use these hooks to add your wrapper <div>:

<?php
function wpse53671_comment_form_before_fields() {
    echo '<div>';
}
add_action( 'comment_form_before_fields', 'wpse53671_comment_form_before_fields' );

function wpse53671_comment_form_after_fields() {
    echo '</div>';
}
add_action( 'comment_form_after_fields', 'wpse53671_comment_form_after_fields' );
?>

(Note: if anything else is hooking into these actions, you may need to adjust the callback priority, so that your tags nest properly.

share|improve this answer
    
worked like a charm :) –  versvs May 31 '12 at 18:01
    
sure, i forgot to explicit what was already implicit: thanks again! –  versvs May 31 '12 at 18:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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