The issue

The comment form, as i planned to design it, will use Bootstrap's input groups and probably input addons. Translating in bare coins, the needed markup for each input is like this:

<section class="form-group">
    <input type="text" class="form-control" id="name" placeholder="Your name" />

Wordpress function comment_form(), as far as i know, doesn't allow this kind of markup. I can give id or classes to the form, to the submit button, but i was not able to find anything that lets me add wrapping elements and classes to inputs.

The question

Since i don't want to write my own function, cause i'm concerned about plugins not being able to function properly, is there a way to do this using as much native functions as possible? Thank you.


To avoid any misunderstanding, if not clear, i'm not asking a question about Bootstrap itself, but just how should i generate a precise markup with Wordpress.

  • @WebElaine And that won't cause issues? After all it is writing a custom function instead of using wp's one – Daniele Squalo May 26 '17 at 14:53
  • Most sites are customized at least a little, whether it's custom functions or filters. Shouldn't cause issues unless you let the site sit there for 5 years without updating your code to later standards. :) – WebElaine May 26 '17 at 15:05

Yeah this should be possible using the comment_form_default_fields filter, like so:

apply_filters( 'comment_form_default_fields', $fields );

$fields = array( 'name' => '<section class="form-group">
    <input type="text" class="form-control" id="name" placeholder="Your name" />

Just remember to add any other fields that you want to add into that array too.

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.