When a user uses the password reset functionality in WordPress, they are asked to enter their email and click confirm. After doing so, they get the message:
Check your email for the confirmation link, then visit the login page.
I wish to modify this message, and I have found the line of code where the message is written in the wp-login.php file:
if ( 'confirm' === $_GET['checkemail'] ) {
$errors->add(
'confirm',
sprintf(
/* translators: %s: Link to the login page. */
__( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
wp_login_url()
),
'message'
);
}
Changing the message there works fine and all, but am I correct in assuming that it would be overwritten as soon as WordPress is updated?
If so, my questions are:
- Is it possible for me to modify this message with a function that I could put in my theme’s functions.php file so that it won’t be overwritten by future WP updates?
- Can I also have a translation for my new message? If I edit the translation file in the /wp-content/languages folder, I assume it would also be overwritten by an update?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If there is no filter to change the content, the other option is to add a function hooked to gettext – for example:
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function wpse_382257_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Check your email for the confirmation link, then visit the login page.' :
$translated_text = __( 'SOMETHING ELSE', 'text-domain' );
break;
case 'Another' :
$translated_text = __( 'Whatever..', 'text-domain' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wpse_382257', 20, 3 );
ref: https://developer.wordpress.org/reference/hooks/gettext/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0