How to change the default registration email ? (plugin and/or non-plugin)

  • After a new user registration, WP sends out an email with the login / password, and a link to the login page.

    Is there a way to change this defaut email template? I'd also like to change the subject and sender.

    Edit : For anyone interested, here is a plugin solution.

  • Bainternet

    Bainternet Correct answer

    10 years ago

    The new user email is sent using the wp_new_user_notification() function. This function is pluggable, which means that you can overwrite it:

    // Redefine user notification function
    if ( !function_exists('wp_new_user_notification') ) {
        function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
            $user = new WP_User($user_id);
            $user_login = stripslashes($user->user_login);
            $user_email = stripslashes($user->user_email);
            $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "\r\n\r\n";
            $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
            $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
            @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
            if ( empty($plaintext_pass) )
            $message  = __('Hi there,') . "\r\n\r\n";
            $message .= sprintf(__("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
            $message .= wp_login_url() . "\r\n";
            $message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
            $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n\r\n";
            $message .= sprintf(__('If you have any problems, please contact me at %s.'), get_option('admin_email')) . "\r\n\r\n";
            $message .= __('Adios!');
            wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);

    Note: Overriding pluggable functions cannot be done in the theme functions.php file. WP's pluggable file is already loaded by that point so the function would be defined by WP (i.e. the default). Your custom version must load before this happens, which means you must load it in a custom plugin file.

    @Bainternet I cannot seem to get this to work, I have added this to my functions file, but the standard email keeps sending. I'm on multisite, but that shouldn't matter, right?

    OK got it now, it only seems to work as a separate plugin, not when you add it to your `functions.php` file. Now it works perfect, thanks again for that nice piece of code!

    Does it works for multisite too? I can see multisite has bunch of functions inside ms-functions.php for sending notification email.

    Multisite uses `wpmu_signup_user_notification` I think.

    This answer is several years old. The accepted answer doesn't work for me. (Adding it to functions.php has makes no difference to any of the emails sent when a new user registers.) Should I post a new question?

    In the end I found some code that worked for me in this tutorial:

    To address the comments regarding it not working in functions.php, that's because you can't load a custom version of a pluggable function that late. It has nothing to do with the answer being old. You must define your custom function before the WP version is loaded. When loaded in functions.php, the default version of the plugin is already defined. You have to load it *as a plugin* (there's no difference between the answer given and the link Kit posted other than the extra step of loading it as a plugin).

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM