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 there, this 1 not working! ;(
Can you provide more details as in what you tried so far and what issue you are facing?
I tried to use this method to replace the text on my registration page: https://staging78.moesonson.com/en/register
the text is next to the checkbox ‘Subscribe to the lastest news from us’
But it is not working.. do you know why?
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!