• Hello. checkbox is not selected by default. How do I do this selected? Automatically for visitors

    cookies' => '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />'

    I tried that but it didn’t. checked=”checked”

    how can I do that? thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the “comment_form_field_cookies” filter to insert the checked attribute, but be sure it is not already there as WP sets it for returning commenters. Also be sure you are not running afoul of of any privacy regulations in your jurisdiction. Default acceptance could be seen as contrary to the opt-in concept.

    Thread Starter devrekli

    (@devrekli)

    how can I do that? which code should I change? or what code should I add? thanks

    Moderator bcworkz

    (@bcworkz)

    I cannot offer complete working code, but I can give you a starting point. Add the completed version to functions.php of your theme (better yet child theme).

    add_filter('comment_form_field_cookies', function() {
      return 'proper field HTML goes here';
    });

    You really should not arbitrarily add the checked attribute to all comment forms because if a user opts out they should not see the checkbox checked any more. There’s no simple way to separate new users from opt out users. Opt in users of course have a cookie placed, so with the default being unchecked, separating opt out from new is not necessary.

    Thread Starter devrekli

    (@devrekli)

    thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘wordpress comment-form-cookies-consent, checkbox selected?’ is closed to new replies.