How to customize comment checkbox?

In a comment form, WordPress by default provides a checkbox text as “Save my name, email, and website in this browser for the next time I comment.” What if you want to change that to something else, more catchy or custom to your needs?

Well, that is possible using gettext filter. Simply put below code in your theme’s functions.php file and feel free to use your custom text like showed below:

add_filter( 'gettext', 'theme_change_comment_cookie_label', 20, 3 );
function theme_change_comment_cookie_label( $translated_text, $text, $domain ) {
    if ( is_singular() ) {
        switch ( $translated_text ) {
            case 'Save my name, email, and website in this browser for the next time I comment.' :
                $translated_text = __( 'Set a cookie to save my name and email to use for future comments.', 'twentytwenty' );
                break;
        }
    }
    return $translated_text;
}

In case you want to update labels of other fields in your comment form then you can refer below code snippet:

add_filter( 'gettext', 'theme_change_comment_cookie_label', 20, 3 );
function theme_change_comment_cookie_label( $translated_text, $text, $domain ) {
    if ( is_singular() ) {
        switch ( $translated_text ) {
			case $translated_text == 'Name' :
				$translated_text = __( 'Your Name', 'twentytwenty' );
				break;
            case $translated_text == 'Email' :
				$translated_text = __( 'Your Email', 'twentytwenty' );
				break;
			case $translated_text == 'Save my name, email, and website in this browser for the next time I comment.' :
				$translated_text = __( 'Set a cookie to save my name and email to use for future comments.', 'frontier' );
			break;		
        }
    }
    return $translated_text;
}

5 Comments

Hi Moesonson, the code snippet I shared is to update the checkbox label in comment form. The one you are trying to change is login/register form and that is why it is not working.

Very nice article. It helped me edit the last part I needed to edit in the default WordPress comment form. Many thanks!

Leave a Reply

%d bloggers like this: