What’s wrong with Customizing new user notification email by add_filter?

There is actually nothing wrong with the code that you have (I tested it as you have it above and it works fine).

But you have to account for some additional possibilities:

  1. The wp_new_user_notification() function is a pluggable function. So it can be replaced by a plugin or by custom code. And if it is replaced, there is a possibility that the custom version of the function lacks the wp_new_user_notification_email filter hook.
  2. Possibly another filter already exists hooked to this same filter, but at a earlier priority (<10) and it redirects or otherwise exits the process. That would be bad form, but it is possible. This isn’t all that likely the problem, but it is possible so that’s why I mention it.
  3. The possibility exists you are targeting the wrong function. We’re assuming that the email is the default WP registration, but you didn’t state that specifically. If you’re doing something where there’s a custom registration and/or some other process, it doesn’t necessarily go through wp_new_user_notification().

With those possibilities, I would recommend you do the following:

  1. Review your theme to make sure this is the only instance of a wp_new_user_notification_email filter.
  2. Disable ALL plugins.
  3. Re-test with all plugins deactivated.