1

The <input> tags does not allow/support many CSS properties, so I want to change it to <button>.

How can I get that button and apply a filter to it?

2
  • Just curious, what CSS properties do you have in mind?
    – birgire
    Oct 23, 2015 at 8:15
  • Generally pseudos like :before are not working.
    – thednp
    Oct 23, 2015 at 8:29

1 Answer 1

3

You should be able to change the HTML structure for the comment form's submit, with the comment_form_defaults filter.

Here's an untested example:

add_filter( 'comment_form_defaults', function( $defaults )
{
    // Edit this to your needs:
    $button = '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />';

    // Override the default submit button:
    $defaults['submit_button'] = $button;

    return $defaults;
} );

where you adjust the $button to your needs.

There's also the comment_form_submit_button filter:

add_filter( 'comment_form_submit_button', function( $submit_button, $args )
{
    // Override the submit button HTML:
    $button = '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />';

    return sprintf(
        $button,
        esc_attr( $args['name_submit'] ),
        esc_attr( $args['id_submit'] ),
        esc_attr( $args['class_submit'] ),
        esc_attr( $args['label_submit'] )
     );

}, 10, 2 );

It should even be possible with the comment_form_submit_field filter, but it contains hidden fields as well, so it might not be as helpful as the other filters.

2
  • Thanks so much, the first method works, please update the second method add_filter( 'comment_form_submit_button', function( $submit_button, $args ){} I would like to use this one. The $submit_button = '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'; copied to the second method isn't working.
    – thednp
    Oct 23, 2015 at 8:20
  • Great. I updated the example with the comment_form_submit_button filter. @thednp
    – birgire
    Oct 23, 2015 at 10:23

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.