Site logo

Archived topic

Comment Cookies Consent Label

10 replies · Started by Michael on February 25, 2020

Viewing posts 1–11 of 11

Hi there,

This should do it:

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" 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 );

Tom, you're the bomb. That works perfectly. Thank you very much :)

You're very welcome :)

Hello Tom,

I wonder if the solution provided in your post #1176782 is translatable in other languages with a plug-in like WPML.

Thank you

Hi Simon,

Not sure if it will compatible with the plugin, but you can have it a try, change this part:
Save my name and email in this browser for the next time I comment. to your language.

Hi Ying,
Thank you for your reply.
I must be wrong but I'm asking the question because in the solution proposed by Tom I don't see the syntax to make a text translatable.
I saw several times that to be translatable, a string must be written inside __() in your theme.
Best regards

Hi Simon,

Yeah that's correct. having it inside __() w/ a textdomain allows it to be translatable.

Example:

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" value="yes"' . $consent . ' />' . 
        '<label for="wp-comment-cookies-consent">' . __( 'Save my name and email in this browser for the next time I comment.', 'generatepress' ) . '</label>
    </p>';

    return $fields;
}, 20 );

Thank you, it is more clear for me now.

Best regards

Nice one. No problem. :)

Hey Tom,

Assuming the code you shared is still valid, where would I add in GeneratePress?

Thanks,
Mike

This archived topic is closed to new replies.