Archived topic
Save Name/Email Comments Checkbox Default State
3 replies · Started by Michael on April 6, 2020
Hi guys,
Please can you tell me how I can set the default state to checked?
https://www.dropbox.com/s/wwg77kj8bg8odct/comments-checkbox.jpg?dl=0
Thank you for your help.
Michael.
Hi there,
This is handled by WordPress itself so something like this might help:
https://www.webfulcreations.com/remove-or-edit-save-my-name-email-and-website-in-this-browser-for-the-next-time-i-comment/
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox
Hi Leo, thank you. This worked, for anyone who might need it in the future (I adjusted the code that was hiding the website input):
add_filter( 'comment_form_default_fields', function( $fields ) {
$commenter = wp_get_current_commenter();
$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" checked="checked" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">Save my name and email in this browser for the next time I comment.</label></p>';
return $fields;
}, 20 );
Glad you've figured out :)