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.
Post Views: 4
If you check out the source of the function
comment_form()
, you’ll see it doesn’t even print a class on the input;I’m guessing you need to add a class for styling? Why not modify your CSS to just;
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 😉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:No need to do extra hard work. (Edited the Codex too) 🙂
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.
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:
Simple. Or, if you prefer to use classes only for some reason:
There’s no advantage I can see, from any angle, to putting a class on the comment form’s submit button.
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.
the $args i used are
I suggest those who have this problem to set a style for “post-comment” id, like what i did:
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:Then change line
1576
to the following:Now you have a new default value called
class_submit
that can be included in the$args
array parameter on thecomment_form()
function:Happy Wording!