1

再会。我最近试图弄清楚在评论框中添加自定义字段它工作正常。我仍然需要知道如何在评论框后添加自定义字段。我不知道该怎么做。

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;
}

当我尝试上面的代码时,这种方式本身就出现了。 在此处输入图像描述

我如何才能在评论框旁边显示此字段。任何建议都会很棒。

编辑: 在此处输入图像描述 谢谢,维基

4

1 回答 1

2

用表单关闭之前发生的替换你add_filter的,即使用钩子:add_actioncomment_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>';
}

您应该给函数一个更全面的名称(add_input_privacy)

于 2013-08-12T06:51:04.220 回答