Vignesh Pichamani
Vignesh Pichamani

Reputation: 8070

Add a Custom Field in Comment Box next to the Text area in wordpress

Good Day. I Recently try to figure out for adding the custom field in the comment box it working fine. Still I need to know how to add the custom field after the comment box. I am not sure how to do this.

add_filter('comment_form_defaults', 'change_comment_form_defaults');

function change_comment_form_defaults($default) {

    $commenter = wp_get_current_commenter();

    $default['fields']['comment'] .= '<p class="comment-form-author">' .
            '
<input type="checkbox" style="margin:0px;height:auto;width:auto; position:relative;" name="privacy" value="1"/> I agree to the Terms of Use and Privacy Policy</p>';
    return $default;
}

When i Tried this above code this way itself is appear. enter image description here

How can i do this to show this field next to the comment box. Any suggestion would be great.

EDITED: enter image description here Thanks, vicky

Upvotes: 1

Views: 2178

Answers (1)

Nabil Kadimi
Nabil Kadimi

Reputation: 10394

Replace your add_filter with an add_action which happens just before the form closes, i.e by using the hook comment_form:

add_action('comment_form', 'add_input_privacy');
function add_input_privacy() {
    $commenter = wp_get_current_commenter();
    echo '<p class="comment-form-author"><input type="checkbox" style="..." name="privacy" value="1"/>I agree...</p>';
}

You should give the function a more comprehensive name (add_input_privacy)

Upvotes: 2

Related Questions