Using WordPress ‘comment_form_before_fields’ PHP action

The comment_form_before_fields WordPress PHP action allows you to add custom content or functionality before the comment fields in the comment form, excluding the textarea.


add_action('comment_form_before_fields', 'your_custom_function');
function your_custom_function() {
    // Your custom code here


  • None

More information

See WordPress Developer Resources: comment_form_before_fields


Add a custom text before the comment fields

This example adds a custom text before the comment form fields.

add_action('comment_form_before_fields', 'add_custom_text');
function add_custom_text() {
    echo '<p>Please fill out the fields below to submit your comment.</p>';

This example adds a consent checkbox before the comment fields, asking the user to agree to the website’s terms and conditions.

add_action('comment_form_before_fields', 'add_consent_checkbox');
function add_consent_checkbox() {
    echo '<input type="checkbox" name="consent" required> I agree to the <a href="/terms">Terms and Conditions</a><br>';