Friendlier Subjects for Account Emails
Gives WordPress's new account, password changed and email address changed emails friendlier subjects of your own, without touching the rest of the message.
Opens WPIDE on
Code
$wpide_core_subjects = array(
'new_user' => 'Welcome to %s – set up your account',
'password_changed' => 'Your %s password was changed',
'email_changed' => 'Your %s email address was changed',
);
$wpide_site_name = function () {
return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
};
add_filter( 'wp_new_user_notification_email', function ( $email ) use ( $wpide_core_subjects, $wpide_site_name ) {
if ( isset( $wpide_core_subjects['new_user'] ) ) {
$email['subject'] = sprintf( $wpide_core_subjects['new_user'], $wpide_site_name() );
}
return $email;
} );
add_filter( 'password_change_email', function ( $email ) use ( $wpide_core_subjects, $wpide_site_name ) {
if ( isset( $wpide_core_subjects['password_changed'] ) ) {
$email['subject'] = sprintf( $wpide_core_subjects['password_changed'], $wpide_site_name() );
}
return $email;
} );
add_filter( 'email_change_email', function ( $email ) use ( $wpide_core_subjects, $wpide_site_name ) {
if ( isset( $wpide_core_subjects['email_changed'] ) ) {
$email['subject'] = sprintf( $wpide_core_subjects['email_changed'], $wpide_site_name() );
}
return $email;
} );
Notes
Use %s for the site name; remove a line to keep WordPress's default subject for that email.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.