wp_new_user_notification_email

Home » Hooks » wp_new_user_notification_email

The wp_new_user_notification_email hook is a WordPress filter that allows developers to customize the email sent to newly registered users. By default, WordPress sends an email to the user with their login credentials. However, with the help of this hook, developers can modify the email content and add new information, such as website-specific policies or links to important pages.

This hook is ideal for websites that require users to complete certain tasks after registration, such as account verification or profile completion. Developers can use this hook to add custom instructions in the registration email, guiding users to complete these tasks.

Here is an example usage code for wp_new_user_notification_email:

function custom_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
    //Modify the email subject
    $wp_new_user_notification_email['subject'] = sprintf( __( 'Welcome to %s!' ), $blogname );

    //Modify the email message
    $wp_new_user_notification_email['message'] = sprintf( __( 'Thank you for registering with %s. Please verify your account by clicking on this link: %s' ), $blogname, 'https://example.com/account-verification' );

    //Return the modified email
    return $wp_new_user_notification_email;
}
add_filter( 'wp_new_user_notification_email', 'custom_new_user_notification_email', 10, 3 );

In this example, we have created a function that modifies the email subject and message. The subject is changed to "Welcome to [Website Name]!", and the message now includes a custom message and a link to an account verification page. This way, the user gets additional information with their login credentials. The last line of code adds the filter to the hook, passing our function name and the priority.

Learn More on WordPress.org

WordPress snippets using the wp_new_user_notification_email hook

Register an account to save your snippets or go Pro to get more features.