How do I add a class to the comment submit button? The simplified function comment_form(array('id_submit'=>'buttonPro')); obviously only changes the id and class_submit does not seem to exist.

I have read through both Otto's and Beau's writeups but to no avail.

7 Answers 7


If you check out the source of the function comment_form(), you'll see it doesn't even print a class on the input;

<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

I'm guessing you need to add a class for styling? Why not modify your CSS to just;

input.submit, #buttonPro {
    /* some awesome style */

Otherwise I guess the 'easiest' solution would be to simply copy the function to your functions.php, rename it, add in a class argument & print, and use that instead - which you can find here ;)

  • Thanks for the advice and comment form. :) I have a theme option that helps style the theme based on if it is a light or dark ui. If there was a simple function that could add a class I could wrap that function in an if:isdark kind of statement. I'll have to look more closely at longform function you provided.
    – MTT
    Jun 10, 2011 at 16:22
  • 1
    In my Oenology Theme, I output custom CSS based on whether the current color scheme is dark or light. Here's the \functions\options.php file that does all of the heavy lifting. Jun 10, 2011 at 16:43

From WordPress Version 4.1 (trac ticket #20446) it's now added to pass your own class as an argument of comment_form($args) using 'class_submit' array key:

$args = array( 'class_submit' => 'btn btn-default' );

No need to do extra hard work. (Edited the Codex too) :)

  • 1
    This should be the correct answer.
    – Christine Cooper
    Apr 11, 2015 at 19:00

I'm working with the Foundation framework as well. I've found that the easiest way to add a class to a non-filterable element is to do it with jQuery.

jQuery(document).ready(function($) { //noconflict wrapper
});//end noconflict
  • 1
    Never thought of that. That's hacky, but cleaner than hacking core. Copying your code right now! Nov 1, 2012 at 19:28
  • I already have a heavily used jquery site. So adding this chunk of code was really easy and worked like a charm.
    – Jamie
    Feb 10, 2013 at 4:03
  • Just a note for future readers, its very possible that your styling will look very distorted on each page load depending on js load time, i would avoid doing this sort of class modification where possible
    – Cacoon
    May 29, 2018 at 21:53

Why do you need a class on the submit button? You can give it an ID, as you have discovered, and that's all you need for styling it.


Then to style it:

input#buttonPro {...}

Simple. Or, if you prefer to use classes only for some reason:

.form-submit input {...}

There's no advantage I can see, from any angle, to putting a class on the comment form's submit button.

  • 1
    Absolutely. If you need greater specificity, target your CSS selectors higher up. Look at the ID or class of the container that holds the comment reply form, or that holds the entire comments markup. Also, there should only ever be one comment reply form on any given page, so I don't see the harm in targeting the submit button ID, passed via argument, for applying CSS. Jun 10, 2011 at 16:41
  • 5
    With all due respect, I disagree. I have a website+blog. I have defined a class & used it for all the buttons. Also I have different states for the buttons (normal, hover). If I were to not apply a class to the comment button, then that would mean that I have to target the blog comment button by ID and start adding the selector right next to the already defined class (comma separated). That means, I am unable to make use of already defined class & this is not preferred. Simply applying the class name to button makes life all the more easy without having me to add ID manually & keeps it simple.
    – Devner
    Nov 16, 2012 at 19:19
  • Devner: You're using CSS exactly backwards from the way it is intended to be used. Class names and ID's should be semantically defined, not defined according to how you want them styled. The whole point is to be able to change the CSS instead of changing the HTML, because the HTML is often generated, while the CSS is much easier to change.
    – Otto
    Nov 17, 2012 at 0:28
  • 2
    Some frameworks such as Bootstrap provide button styles on the class e.g .btn - although not a big problem, it would make things easier if a class could be added. Sep 18, 2013 at 16:11
  • 2
    I know this is several years old at this point, but I'm surprised by this statement: "There's no advantage I can see, from any angle, to putting a class on the comment form's submit button." Why add an additional ID to the stylesheet when an existing class (say for button styling) can provide the styling you need? Oct 15, 2013 at 14:51

I was searching for the same solution and at last i found the solution, the below code worked perfectly for me, I wanted to add "btn btn-primary" class to the submit button in comment form.

comment_form( $args );
$form = ob_get_clean(); 
$form = str_replace('class="comment-form"','class="comment-form"', $form);
echo str_replace('id="submit"','class="btn btn-primary"', $form);

the $args i used are

$args = array(
'comment_field' => '<p class="comment-form-comment"><label for="comment">Comment</label> <textarea class="form-control" id="comment" name="comment" cols="35" rows="12" aria-required="true"></textarea></p>',
'fields'        => array(
    'author' => '<p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input class="form-control input-comment-author" id="author" name="author" type="text" value="" size="30" aria-required="true"></p>',
    'email'  => '<p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input class="form-control input-comment-email" id="email" name="email" type="text" value="" size="30" aria-required="true"></p>',
    'url'    => '<p class="comment-form-url"><label for="url">Website</label> <input class="form-control input-comment-url" id="url" name="url" type="text" value="" size="30"></p>',
'cancel_reply_link' => '<button class="btn btn-danger btn-xs">Cancel reply</button>',
'label_submit' => 'Post Comment',);

I suggest those who have this problem to set a style for "post-comment" id, like what i did:

#post-comment {
background: none repeat scroll 0 0 transparent;
border: 1px solid #FFFFFF;
padding: 8px 20px;
float: left;}

good luck! :)


I'm going to reply (late) since I was looking for an answer to this and decided to tackle it myself.

First, to answer the question "why add a class?"... In my case, I chose to use a UI framework called Foundation to design my most recent theme for my personal blog. I chose it precisely because I like its style for buttons. However, it requires the developer to add a class to an <input> button, and I didn't realize that couldn't be done in WP until I was almost completely done with the theme!

So, here's what I did. I had to edit the /wp-includes/comment-template.php file, so use at your own risk because it could be wiped out during a WP upgrade.

After line 1540 (as of version 3.2.1) add the following line:

'class_submit'         => 'submit',

Then change line 1576 to the following:

<input name="submit" class="<?php echo esc_attr( $args['class_submit'] ); ?>" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />

Now you have a new default value called class_submit that can be included in the $args array parameter on the comment_form() function:

<?php comment_form(
            'class_submit' => __('XXX'),
    ); ?>

Happy Wording!

  • 4
    it's a bad idea to hack core and on this site some people take it personally. Since you are new here, I'm going to take away your down vote that someone else left. But now you know.
    – MTT
    Oct 19, 2011 at 11:50
  • 2
    Alex, Taylor is right. NEVER modify core files! NEVER EVER!
    – Devner
    Nov 16, 2012 at 19:23
  • 2
    Never, modify, core files.
    – Rantiev
    Aug 17, 2014 at 18:25

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