Site logo

Archived topic

Save Name/Email Comments Checkbox Default State

3 replies · Started by Michael on April 6, 2020

Viewing posts 1–4 of 4

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 :)

This archived topic is closed to new replies.