Home » Hooks » comment_form_default_fields

The comment_form_default_fields hook in WordPress is used to modify the default fields of the comment form displayed on a WordPress site. This hook is called within the comment_form function and allows developers to add or remove fields from the comment form.

By default, the comment form displays fields for name, email, website, and comment. However, using this hook, developers can add custom fields to the comment form, such as a phone number or custom message field.

Example usage code:

function add_custom_comment_field($fields) {
    $fields['phone'] = '<p class="comment-form-phone">' .
                        '<label for="phone">' . __( 'Phone' ) . '</label>' .
                        '<input id="phone" name="phone" type="text" size="30" /></p>';
    return $fields;
add_filter( 'comment_form_default_fields', 'add_custom_comment_field' );

In this example, we are adding a custom phone field to the comment form. The add_custom_comment_field function is used to add the phone field to the $fields array. The comment_form_default_fields hook is then used to modify the comment form by adding the custom phone field.

Learn More on

Register an account to save your snippets or go Pro to get more features.