How to Add a class to the WordPress comments submit button

This WordPress feature slipped by me, but since the release of WP 4.1 there is a great and simple new filter that I’ve been watching for a number of years here. Interestingly this ticket was opened 5 years ago today, so some have literally been waiting years! The commentform.php file now has a couple more options available as explained in this changeset.

add_filter( 'comment_form_defaults', 'circlecube_comment_form' );I have been using foundation and bootstrap on sites and have struggled with the best way to add a button class to this button since I wanted it to inherit the frameworks styles for a button. I’ve seen a few ways to go about doing this, like using javascript (ug), or adding an extra button and hiding the original button with css (meh). But now it’s a simple little filter to add to comment_form_defaults.  Just add your desired class value to ‘class_submit’ in the args. I’ve put it into a simple little gist to add a ‘button’ class to my input type equals submit:


function circlecube_comment_form( $args ) {
$args['class_submit'] = 'button'; // since WP 4.1
return $args;
}
add_filter( 'comment_form_defaults', 'circlecube_comment_form' );

view raw

functions.php

hosted with ❤ by GitHub

Leave a Reply