2026年11月14日
2026年11月14日
Customize WordPress Notification Emails: Subject, Body and Recipients
This article is a localized edition of the Japanese original. Read the Japanese original
WordPress sends emails automatically when a user registers, when someone posts a comment, when a password is reset, and so on. If you want subjects and bodies that fit your site, extra recipients, or fewer notifications, you can make those changes with filters that WordPress core provides.
The hook names and arguments in this article were checked against the WordPress core source code (wp-includes/pluggable.php and wp-includes/user.php) as of November 2026.
Where to put the code
Put the code below in your child theme's functions.php, or in a PHP file in wp-content/mu-plugins/ (for example mail-custom.php). If you want the notification settings to survive a theme change, a must-use plugin is the better fit. A must-use plugin file is loaded as soon as it starts with <?php, and it cannot be deactivated from the admin screen.
Which filter changes which email
| Notification email | Recipient | Filter to change it | How to stop it |
|---|---|---|---|
| New user registration (to the admin) | Administration email address | wp_new_user_notification_email_admin |
Return false from wp_send_new_user_notification_to_admin |
| New user registration (to the user, with the set-password link) | The new user | wp_new_user_notification_email |
Do not stop it; the user could not set a password |
| New comment | Post author | comment_notification_subject, comment_notification_text, comment_notification_recipients |
"Settings" → "Discussion", or notify_post_author |
| Comment awaiting moderation | Admin and the post author | comment_moderation_subject, comment_moderation_text, comment_moderation_recipients |
"Settings" → "Discussion", or notify_moderator |
| Password reset | The user | retrieve_password_title, retrieve_password_message, retrieve_password_notification_email |
Do not stop it; resets would no longer work |
| Password changed (to the admin) | Administration email address | wp_password_change_notification_email |
Remove it with remove_action |
| Password changed (to the user) | The user | password_change_email |
Return false from send_password_change_email |
wp_send_new_user_notification_to_admin was added in WordPress 6.1, and retrieve_password_notification_email in 6.0. They are not available in older versions.
Change the sender name and address
By default, emails come from wordpress@your-site-domain with the name "WordPress". You can change both with these filters.
add_filter( 'wp_mail_from', function ( $from_email ) {
return 'no-reply@example.com';
} );
add_filter( 'wp_mail_from_name', function ( $from_name ) {
return 'Sample Site';
} );
Use your site's domain, or a domain with SPF and DKIM set up, as the sender domain. Otherwise your mail is more likely to be flagged as spam. For details, see How to change the WordPress sender email address and our comparison of SMTP plugins.
Change the new user registration emails
Registration emails are built by wp_new_user_notification(), which sends two messages: one to the admin and one to the new user. Both filters receive an array with to, subject, message and headers, so you change only the elements you need and return the array.
// To the admin: change the recipient and body
add_filter( 'wp_new_user_notification_email_admin', function ( $email, $user, $blogname ) {
$email['to'] = 'members@example.com';
$email['subject'] = '[%s] New member registered';
$email['message'] = sprintf(
"A new user has registered.\r\n\r\nUsername: %s\r\nEmail: %s\r\nUser list: %s\r\n",
$user->user_login,
$user->user_email,
admin_url( 'users.php' )
);
return $email;
}, 10, 3 );
// To the user: add a greeting before the original body, which contains the set-password link
add_filter( 'wp_new_user_notification_email', function ( $email, $user, $blogname ) {
$email['subject'] = '[%s] Thank you for registering';
$email['message'] = $user->display_name . ",\r\n\r\nThank you for registering.\r\n\r\n" . $email['message'];
return $email;
}, 10, 3 );
Keep two things in mind.
- The subject is passed through
sprintf()right before sending, so the site title is inserted where%sappears. To put a literal%in the subject, write%%. - The email to the new user contains the link for setting a password. If you replace the whole body, the link disappears and the new user cannot log in. Keep the original body (
$email['message']) as in the example above.
If you only want to stop the email to the admin, this one line is enough.
add_filter( 'wp_send_new_user_notification_to_admin', '__return_false' );
Removing wp_send_new_user_notifications from register_new_user with remove_action also stops the set-password email to the user, so do not use it if you only want to change the admin email.
Change the comment notifications
Whether comment notifications are sent at all is decided first under "Settings" → "Discussion" → "Email me whenever" in the admin screen.
- "Anyone posts a comment": tells the post author about new comments
- "A comment is held for moderation": tells the admin and the post author that a comment is awaiting approval
Change the subject and recipients as follows. The comment ID in the second argument is passed as a numeric string.
// Subject of the new comment notification
add_filter( 'comment_notification_subject', function ( $subject, $comment_id ) {
$comment = get_comment( $comment_id );
return sprintf( '[New comment] "%s"', get_the_title( $comment->comment_post_ID ) );
}, 10, 2 );
// Subject of the moderation notification
add_filter( 'comment_moderation_subject', function ( $subject, $comment_id ) {
$comment = get_comment( $comment_id );
return sprintf( '[Awaiting approval] Comment on "%s"', get_the_title( $comment->comment_post_ID ) );
}, 10, 2 );
// Also send moderation notices to the editor
add_filter( 'comment_moderation_recipients', function ( $emails, $comment_id ) {
$emails[] = 'editor@example.com';
return array_unique( $emails );
}, 10, 2 );
// Do not notify about new comments on posts in the "news" category
add_filter( 'comment_notification_recipients', function ( $emails, $comment_id ) {
$comment = get_comment( $comment_id );
if ( has_category( 'news', (int) $comment->comment_post_ID ) ) {
return array();
}
return $emails;
}, 10, 2 );
If comment_notification_recipients returns an empty array, that notification is not sent. To change the body, add a filter in the same way to comment_notification_text or comment_moderation_text.
Change the password reset email
The email sent from "Lost your password?" is built by retrieve_password(). Change the subject with retrieve_password_title and the body with retrieve_password_message. The body filter receives the reset key ($key) as its second argument, and you build the reset URL from it. Use the same URL format as WordPress core.
add_filter( 'retrieve_password_title', function ( $title, $user_login, $user_data ) {
return sprintf( '[%s] How to reset your password', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) );
}, 10, 3 );
add_filter( 'retrieve_password_message', function ( $message, $key, $user_login, $user_data ) {
$reset_url = network_site_url(
'wp-login.php?login=' . rawurlencode( $user_login ) . "&key=$key&action=rp",
'login'
);
return sprintf(
"Hello %s,\r\n\r\nWe received a request to reset your password.\r\nSet a new password at the following URL:\r\n\r\n%s\r\n\r\nIf you did not request this, you can ignore this email. Your password will not be changed.\r\n",
$user_data->display_name,
$reset_url
);
}, 10, 4 );
- The fourth argument of
add_filter()is the number of arguments your callback accepts. To use all four arguments ofretrieve_password_message, pass10, 4(10 is the priority). - If
retrieve_password_messagereturns an empty string, the email is not sent. - By default, the reset link expires after one day (you can change this with the
password_reset_expirationfilter). If you mention a deadline in the body, keep it consistent with this value.
In WordPress 6.0 and later, you can also use retrieve_password_notification_email, which receives the subject, body, recipient and headers together. For more on the reset email, see How to customize the password reset email.
Change or stop the password change notifications
When a user resets their password, the admin receives a "Password Changed" email (it is not sent when the user who changed the password has the administration email address). This notice is sent by wp_password_change_notification(), which is hooked to the after_password_reset action.
// Change the subject of the admin notice (the subject goes through sprintf, so keep %s)
add_filter( 'wp_password_change_notification_email', function ( $email, $user, $blogname ) {
$email['subject'] = '[%s] A user's password was changed';
return $email;
}, 10, 3 );
// Stop the admin notice
remove_action( 'after_password_reset', 'wp_password_change_notification' );
The confirmation email that a user receives after changing their password on their profile screen can be stopped with send_password_change_email. This email is a clue for users whose password was changed without their knowledge, so think carefully before turning it off.
add_filter( 'send_password_change_email', '__return_false' );
Send HTML email
If you switch everything to text/html with the wp_mail_content_type filter, plain-text emails sent by WordPress core and plugins are also treated as HTML, and their line breaks disappear so the text runs together on one line. Set Content-Type in headers only for the emails you want in HTML.
// Send only the admin new-registration notice as HTML
add_filter( 'wp_new_user_notification_email_admin', function ( $email, $user, $blogname ) {
$email['headers'] = array( 'Content-Type: text/html; charset=UTF-8' );
$email['message'] = sprintf(
'<p>A new user has registered.</p><ul><li>Username: %s</li><li>Email: %s</li></ul><p><a href="%s">Open the user list</a></p>',
esc_html( $user->user_login ),
esc_html( $user->user_email ),
esc_url( admin_url( 'users.php' ) )
);
return $email;
}, 20, 3 );
Pass usernames and email addresses through esc_html(), and URLs through esc_url(), before putting them into the HTML.
Test your changes
- Register a user with a test email address and check both the admin email and the user email
- While logged out, request a reset email from "Lost your password?" and confirm that you can set a new password from the link
- Post a comment and confirm that the notification reaches the recipients you expect
If emails do not arrive at all, the cause is almost always the sending route, not your filters. See What to do when WordPress confirmation emails do not arrive.
Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)