The comment_form_submit_button WordPress PHP filter allows you to modify the HTML markup for the submit button displayed in the comment form.
Usage
add_filter('comment_form_submit_button', 'my_custom_submit_button', 10, 2);
function my_custom_submit_button($submit_button, $args) {
// your custom code here
return $submit_button;
}
Parameters
- $submit_button (string): HTML markup for the submit button.
- $args (array): Arguments passed to
comment_form().
More information
See WordPress Developer Resources: comment_form_submit_button
Examples
Change the submit button text
Change the text displayed on the submit button.
add_filter('comment_form_submit_button', 'my_custom_submit_text', 10, 2);
function my_custom_submit_text($submit_button, $args) {
$submit_button = str_replace('Post a comment', 'Submit your comment', $submit_button);
return $submit_button;
}
Add a custom CSS class to the submit button
Add a custom CSS class to the submit button for styling purposes.
add_filter('comment_form_submit_button', 'my_custom_submit_class', 10, 2);
function my_custom_submit_class($submit_button, $args) {
$submit_button = str_replace('class="submit"', 'class="submit my-custom-class"', $submit_button);
return $submit_button;
}
Add a custom attribute to the submit button
Add a custom attribute, such as data-custom-attribute, to the submit button.
add_filter('comment_form_submit_button', 'my_custom_submit_attribute', 10, 2);
function my_custom_submit_attribute($submit_button, $args) {
$submit_button = str_replace('type="submit"', 'type="submit" data-custom-attribute="example"', $submit_button);
return $submit_button;
}
Change the submit button type
Change the submit button type from submit to button.
add_filter('comment_form_submit_button', 'my_custom_submit_type', 10, 2);
function my_custom_submit_type($submit_button, $args) {
$submit_button = str_replace('type="submit"', 'type="button"', $submit_button);
return $submit_button;
}
Add an icon to the submit button
Add an icon inside the submit button using Font Awesome or similar icon libraries.
add_filter('comment_form_submit_button', 'my_custom_submit_icon', 10, 2);
function my_custom_submit_icon($submit_button, $args) {
$icon = '<i class="fas fa-comment"></i> ';
$submit_button = str_replace('value="Post a comment"', 'value="' . $icon . 'Post a comment"', $submit_button);
return $submit_button;
}