Skip to content

Instantly share code, notes, and snippets.

@butlerblog
Last active July 19, 2021 17:29
Show Gist options
  • Save butlerblog/08aa73c754ee5c1cc86cd29444d38a4c to your computer and use it in GitHub Desktop.
Save butlerblog/08aa73c754ee5c1cc86cd29444d38a4c to your computer and use it in GitHub Desktop.
Change the #wp_mail "to" address based on subject
<?php
/**
* This is a filter for wp_mail(). It checks the subject
* for the presence of a given string (in this case "New
* User Registration"), and if that returns true it
* sets the "to" address/value.
*/
add_filter( 'wp_mail', 'my_wp_mail_filter' );
function my_wp_mail_filter( $args ) {
// Check the message subject for a known string in the notification email.
if ( strpos( $args['subject'], 'New User Registration' ) ) {
// This is the notification email, so change the "to" address.
$args['to'] = '[email protected]';
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment