Adding class to the comment form in Wordpress
UPDATE:
Wordpress finally supports the possibility to add classes to the comments form. See Nabil Kadimi's answer to get an example.
My outdated answer:
Because Wordpress still hasn't supported this option, I've worked out the following workaround:
<?php ob_start(); comment_form(); echo str_replace('class="comment-form"','class="comment-form your-custom-class"',ob_get_clean());?>
Now the standard class comment-form
will be replaced by itself plus the custom class.
In the documentation for the comment_form()
function:
WordPress 4.4.0 Introduced the 'class_form' [...] arguments.
So you would do:
// Output the comment form with a custom class:comment_form ( array( 'class_form' => 'my_custom_class' ) );
One a second thought
I prefer using hooks:
/** * Callback function for the `comment_form_defaults` filter hook * * @param Array $defaults Defaults. * @return Array Defaults modified. */function se_8476425_modify_comment_form_defaults( $defaults ) { $defaults[ 'class_form' ] = 'class1 class2 class3'; return $defaults;};add_filter( 'comment_form_defaults', 'se_8476425_modify_comment_form_defaults' );
This solution is more generic as you can use it to modify the default function behavior and themes you don't "own".
Since wordpress versiĆ³n 4.1 (Dec, 2014) the comment_form function allows to specify a class attribute for the submit button.
Php Code:
$comments_args = array('class_submit' => 'btn btn-default');comment_form($comments_args);
Resultant HTML Button code:
<input name="submit" type="submit" id="submit" class="btn btn-default" value="Submit" />
For reference see the related ticket: https://core.trac.wordpress.org/ticket/20446