zhuanzhou
zhuanzhou

Reputation: 2453

How to remove a comment form field in WordPress?

Most strings and form fields may be controlled through the $args array passed into the function, while you may also choose to use the comment_form_default_fields filter to modify the array of default fields if you'd just like to add a new one or remove a single field. All fields are also individually passed through a filter of the form comment_form_field_$name where $name is the key used in the array of fields.

the above is from the wordpress manual. but i don't follow it well. anyone can give me an example to explain how to remove a field and add a field.

if i want to remove the comment_notes_before. how should i do? thank you.

Upvotes: 1

Views: 851

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52372

function change_fields($fields) {
    //remove a field
    unset($fields['comment_notes_before']);
    //add a field
    $fields['my_field'] = '<p>My New Field HTML</p>';
    //return the modified array of fields
    return $fields;
}

add_filter('comment_form_default_fields','change_fields');

Upvotes: 2

Related Questions