Email PHP Intermediate

Customise the New User Welcome Email

Change the subject and wording of the email new users get with their "set your password" link.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 18 lines
add_filter( 'wp_new_user_notification_email', function ( array $email, WP_User $user, string $blogname ): array {
	// Find the "set password" link WordPress already built.
	preg_match( '#https?://[^\s<>]*action=rp[^\s<>]*#', $email['message'], $m );
	$link = $m[0] ?? wp_login_url();

	$email['subject'] = sprintf( 'Welcome to %s', $blogname );
	$email['message'] = sprintf(
		"Hi %s,\n\nWelcome to %s! Your account is ready.\n\nUsername: %s\n\nSet your password here:\n%s\n\nAfter that, you can log in at %s\n\nSee you inside,\nThe %s team",
		$user->first_name ?: $user->display_name,
		$blogname,
		$user->user_login,
		$link,
		wp_login_url(),
		$blogname
	);

	return $email;
}, 10, 3 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

The default new user email is short and technical: a username and a link. A proper welcome email sets the tone for new members, students or clients.

How it works

wp_new_user_notification_email passes the email as an array with to, subject, message and headers. WordPress has already created the set-password link inside the message, so the snippet finds that link and uses it in the new text.

Everything else, like the recipient and headers, stays as WordPress set it.

Things to watch

  • Keep the set-password link in your message, or new users won’t be able to log in.
  • WooCommerce customers get WooCommerce’s own “Your account has been created” email instead.

How to test it

Add a new user under Users → Add New with “Send the new user an email” ticked. The email should use your subject and wording.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only