Remove or Customize the WordPress Welcome Email

The wordpress welcome email that new users receive is very bare bones and comes across mechanical and somewhat unwelcoming. The subject line of “[site] Your username and password info” is sure to not stir any excitement in the user about joining your site. The contents that merely list the username, password, and website url don’t help at all either.

We’ll take a look at a few options to either stop the WordPress welcome email from sending entirely or how to customize it to be more welcoming and useful for your brand. I’m also including some information on how to do these things if your site is setup to use mandrill for sending instead. All of the following code snippets can be dropped right into your wordpress site’s functions.php file to work. The removal snippets can be dropped in as-is while the email customization ones will need to be modified to suit your site.

Remove the WordPress Welcome Email

To remove the default wordpress welcome email we will hook into ‘phpmailer_init’ to check and intercept emails before they send out. We will check every email being sent for the default welcome email subject line string. If we find a match, then we will remove the email recipients from the email.

/* Remove Default WordPress Welcome Email
********************************************************/
function vc_mailtrap($phpmailer){
    //check if it is using the default welcome email subject line
    if( strpos($phpmailer->Subject, 'Your username and password info') ){
        //remove all the recipients
        $phpmailer->ClearAllRecipients();
    }
}
add_action('phpmailer_init', 'vc_mailtrap');

If you have mandrill hooked up to your site, we will instead need to be hooking into the mandrill functions and use that api to stop the sending. I did not see any options to stop the sending of the message. Also just removing the recipient in this case resulted in an error. My workaround was to hide all the sensitive information and send it to a non-existent email address. This in combination with the original function above stopped it from sending out. The first function is still necessary because mandrill uses regular wp_mail as a fallback if they encounter any issues with sending the message out.

/* Stop Mandrill from Sending Default WordPress Welcome Email
********************************************************/
function vc_stopwelcome($message) {	
    if( strpos($message['subject'], 'Your username and password info') ){
	$message['to']['email'] = 'noreply@madeupwebsiteurl.com';
	$message['to']['name'] = 'nothing';
	$message['subject'] = 'nothing';
	$message['text'] = 'nothing';
	$message['html'] = 'nothing';
    }
    return $message;
}
add_filter( 'mandrill_payload', 'vc_stopwelcome' );

Customize the WordPress Welcome Email

There are of course a few plugins out there that let you customize the welcome emails that WordPress sends out, but I like to keep my plugin count on the lower side. To send the customized email you can use the snippets above with some modifications.

For default WordPress Mail:

/* Customize New User Registration Welcome Email
********************************************************/
function vc_custommail($phpmailer){
    //check if it is using the default welcome email subject line
    if( strpos($phpmailer->Subject, 'Your username and password info') ){
        //edit the content
        $phpmailer->Subject = 'Welcome to Vincoding.com';
        $phpmailer->Body    = 'I hope you find the <strong>awesome</strong> code snippets to be useful!;
        $phpmailer->AltBody = 'I hope you find the awesome code snippets to be useful!';
    }
}
add_action('phpmailer_init', 'vc_custommail');

For Mandrill:

/* Customize Mandrill Welcome Email
********************************************************/
function vc_stopwelcome($message) {	
    if( strpos($message['subject'], 'Your username and password info') ){
	$message['subject'] = 'Welcome to Vincoding.com';
	$message['text'] = 'I hope you find the awesome code snippets to be useful!';
	$message['html'] = 'I hope you find the <strong>awesome</strong> code snippets to be useful!';
    }
    return $message;
}
add_filter( 'mandrill_payload', 'vc_stopwelcome' );

You can also disable the default registration welcome emails as outlined above and then hook into ‘user_registration’ to then send your own email in a separate function with the code snippet below.

/* Custom WordPress Welcome Email
********************************************************/
function vc_registration_email_alert( $user_id ) {
    $user    = get_userdata( $user_id );
    $email   = $user->user_email;
	$subject = 'Welcome to Vincoding.com';
	$message = 'I hope you find the awesome code snippets to be useful!';
    wp_mail( $email, $subject, $message );
}
add_action('user_register', 'vc_registration_email_alert', 10, 1 );

Now you have all the tools you need to customize the WordPress Welcome email with either the default WordPress mailing system or Mandrill. It’s all easy to implement so give it a try and make those welcome emails actually feel welcoming!

Comments

  1. Worked like a charm! — Remove the WordPress Welcome Email
    Only had to change ‘Your username and password info’ to ‘Your username and password’

    Thanks!

  2. Kennon Brown says

    Beautiful! Small, adds no overhead, works a treat!
    Thank you.

Speak Your Mind

*