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_filteryourをadd_action、フォームが閉じる直前に発生する に置き換えます。つまり、 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>';
}

関数にもっと包括的な名前を付ける必要があります (add_input_privacy)

于 2013-08-12T06:51:04.220 に答える