Using WordPress ‘comment_form_submit_field’ PHP filter

The comment_form_submit_field WordPress PHP filter allows you to modify the submit field for the comment form, including the submit button, hidden fields, and any wrapper markup.

Usage

add_filter('comment_form_submit_field', 'your_custom_function', 10, 2);
function your_custom_function($submit_field, $args) {
    // your custom code here
    return $submit_field;
}

Parameters

  • $submit_field: string – HTML markup for the submit field.
  • $args: array – Arguments passed to comment_form().

More information

See WordPress Developer Resources: comment_form_submit_field

Examples

Change submit button text

Change the text of the submit button to “Send Comment”.

add_filter('comment_form_submit_field', 'change_submit_button_text', 10, 2);
function change_submit_button_text($submit_field, $args) {
    $submit_field = str_replace('Post a comment', 'Send Comment', $submit_field);
    return $submit_field;
}

Add a custom CSS class to the submit button

Add the ‘custom-submit’ CSS class to the submit button.

add_filter('comment_form_submit_field', 'add_custom_css_class', 10, 2);
function add_custom_css_class($submit_field, $args) {
    $submit_field = str_replace('class="submit"', 'class="submit custom-submit"', $submit_field);
    return $submit_field;
}

Add a data attribute to the submit button

Add a custom data-submit attribute to the submit button.

add_filter('comment_form_submit_field', 'add_data_attribute', 10, 2);
function add_data_attribute($submit_field, $args) {
    $submit_field = str_replace('type="submit"', 'type="submit" data-submit="custom"', $submit_field);
    return $submit_field;
}

Wrap the submit button in a div

Wrap the submit button in a div with a custom class ‘custom-submit-wrapper’.

add_filter('comment_form_submit_field', 'wrap_submit_button', 10, 2);
function wrap_submit_button($submit_field, $args) {
    $submit_field = '<div class="custom-submit-wrapper">' . $submit_field . '</div>';
    return $submit_field;
}

Remove the hidden fields from the submit field

Remove the hidden fields from the submit field markup.

add_filter('comment_form_submit_field', 'remove_hidden_fields', 10, 2);
function remove_hidden_fields($submit_field, $args) {
    $submit_field = preg_replace('/<input type="hidden"[\s\S]*?\/>/', '', $submit_field);
    return $submit_field;
}