Last updated on September 25, 2023

Change the “Leave a Reply” Text in Comments

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Change the "Leave a Reply" Text.

To change the “Leave a Reply” text in comments, you can use the comment_form_defaults filter hook to modify the default arguments passed to the comment_form() function. Within this filter, you can update the title_reply argument to change the text.

Here’s an example code snippet that demonstrates how to change the “Leave a Reply” text to “Join the Discussion”:

function wpsnippets_change_comment_form_title( $defaults ) {
    $defaults['title_reply'] = 'Join the Discussion';
    return $defaults;
}
add_filter( 'comment_form_defaults', 'wpsnippets_change_comment_form_title' );

You can add this code to your theme’s functions.php file or in a custom plugin. After adding this code, the “Leave a Reply” text in the comments section will be replaced with “Join the Discussion”.

This code snippet can be useful when you want to customize the text displayed in the comments section of your WordPress site. It allows you to provide more specific instructions or encourage users to engage in discussions.

Examples

Example 1: Changing the “Leave a Reply” text in comments using the comment_form_defaults filter

This code example demonstrates how to change the default “Leave a Reply” text in WordPress comments by modifying the comment_form_defaults filter.

function wpsnippets_change_comment_form_defaults( $defaults ) {
    $defaults['title_reply'] = 'Share your thoughts';
    return $defaults;
}
add_filter( 'comment_form_defaults', 'wpsnippets_change_comment_form_defaults' );

In this code, we define a custom function wpsnippets_change_comment_form_defaults that accepts the $defaults array as a parameter. We modify the title_reply key of the $defaults array to set our desired text. Finally, we return the modified $defaults array. The add_filter function is used to hook our custom function to the comment_form_defaults filter.

Example 2: Changing the “Leave a Reply” text in comments using the comment_form_default_fields filter

This code example demonstrates an alternative method to change the “Leave a Reply” text in WordPress comments by modifying the comment_form_default_fields filter.

function wpsnippets_change_comment_form_default_fields( $fields ) {
    $fields['title_reply'] = 'Join the conversation';
    return $fields;
}
add_filter( 'comment_form_default_fields', 'wpsnippets_change_comment_form_default_fields' );

In this code, we define a custom function wpsnippets_change_comment_form_default_fields that accepts the $fields array as a parameter. We modify the title_reply key of the $fields array to set our desired text. Finally, we return the modified $fields array. The add_filter function is used to hook our custom function to the comment_form_default_fields filter.

Example 3: Changing the “Leave a Reply” text in comments using the gettext filter

This code example demonstrates another approach to change the “Leave a Reply” text in WordPress comments by modifying the gettext filter.

function wpsnippets_change_comment_reply_text( $translated_text, $untranslated_text, $domain ) {
    if ( $untranslated_text === 'Leave a Reply' ) {
        $translated_text = 'Add your comment';
    }
    return $translated_text;
}
add_filter( 'gettext', 'wpsnippets_change_comment_reply_text', 10, 3 );

In this code, we define a custom function wpsnippets_change_comment_reply_text that accepts three parameters: $translated_text, $untranslated_text, and $domain. We check if the $untranslated_text matches the default “Leave a Reply” text and modify the $translated_text accordingly. Finally, we return the modified $translated_text. The add_filter function is used to hook our custom function to the gettext filter.

Last updated on September 25, 2023. Originally posted on October 17, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *