How to Change WordPress Registration Error MessagesPRO

If you’re looking to customize the error messages displayed during the user registration process in WordPress, a powerful tool at your disposal is the gettext WordPress filter hook. This hook allows for the interception and modification of text output by WordPress, including error messages, before they’re shown to the user. By leveraging gettext, you can tailor the registration error messages to better fit your site’s tone, provide more detailed information, or translate messages into different languages.

An example of using this filter hook is shown below:

function my_gettext_hook_function( $translated_text, $text, $domain ) {

    if ('default' === $domain) {

        switch ( $translated_text ) {

            case 'Sorry, that email address is already used!':

                $translated_text = 'That email is already registered. Please try another.';
                break;

            case 'Cannot create a user with an empty login name.':

                $translated_text = 'The username is empty.';
                break;
        }
    }

    return $translated_text;
}

add_filter( 'gettext', 'my_gettext_hook_function', 20, 3 );

Error messages returned from the wp_insert_user function include:

  • Cannot create a user with an empty login name.
  • Nicename may not be longer than 50 characters
  • Not enough data to create this user.
  • Sorry, that email address is already used!
  • Sorry, that username already exists!
  • Sorry, that username is not allowed.
  • User URL may not be longer than 100 characters.
  • Username may not be longer than 60 characters.

Other error messages generated by WS Form under the ws-form-user domain for registration include:

  • Password not specified.
  • Passwords do not match.

The WS Form User Management add-on allows you to create custom WordPress forms for user registration.