Page Builder Summit Limited Time Offer - 20% OFF! Use coupon PBS20 - View Details

How to Change WordPress Login Error MessagesPRO

This knowledge base article relates to the WS Form User Management add-on. Included with the Agency edition or buy separately for other editions.

If you’re looking to customize the error messages displayed during the user login 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 login 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 with the WS Form User Management login template is shown below:

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

    if ('ws-form-user' === $domain) {

        switch ( $text ) {

            case 'Incorrect password.':

                $translated_text = 'The password entered is incorrect. Please try again.';
                break;

            case 'Invalid email address.':

                $translated_text = 'The email address entered is incorrect. Please try again.';
                break;
        }
    }

    return $translated_text;
}

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

Error messages generated by WS Form under the ws-form-user domain for login include:

  • Empty password.
  • Empty username.
  • Incorrect password.
  • Invalid email address.
  • Invalid username.

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