The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Add a Custom Login Error Message in WordPress

Shared by Amit Dholiya · October 23, 2026 · @login_errors

9 views
Back to Snippets

Steps

  1. Add the PHP code to your child theme’s functions.php file or the Code Snippets plugin.

  2. Save and activate the snippet.

  3. Visit the WordPress login page and test with invalid login credentials.

Hook Used

– login_errors — Filters the error message displayed on the WordPress login screen.

Type: WordPress Login Customization

Output: WordPress displays your custom error message instead of its default login error details.

Why use this snippet? It provides consistent login feedback and avoids revealing whether a username or password was incorrect.

Customize: Replace the message inside the quotes with your preferred text.

function custom_login_error_message() {
    return 'Login failed. Please check your username and password and try again.';
}
add_filter( 'login_errors', 'custom_login_error_message' );

Tested on

WordPress 6.8

Reported by the author on October 23, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.4. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by