How to Display Custom Error Messages in WordPress

Thus far, using password forms is considered the best practice to protect your WordPress site. Thanks to it, only users who enter correct passwords will be granted access to your private area.

By default, WordPress displays an error message soon after detecting the wrong input. However, it fails to satisfy WordPress site owners as not only it’s monotonous but also accidentally shows hints for bad guys to attack your site more easily.

Understanding these concerns, in today’s post, we’ll dive into how to display custom error messages in WordPress for login forms. In addition to being guided on how to customize your own error message, you’ll know the best way to remove the login hints from default messages.

Prefer visual content? Let’s check our detailed tutorial video!

Display Custom Error Messages in WordPress Admin Login Forms

By default, the error message will be displayed based on the field that has been wrong inputted. For example:

When you enter an incorrect username, an “Unknown username. Check again or try your email address” message will display.

In case you input the correct username but not the password, there’s also an error message displayed right away above the login form.

Though these detailed error messages can help you address where your input data was wrong, they raise a potential risk as unexpected users can sneak your password hints and attempt to access your private area.

If that’s the case, you should consider customizing these messages to tighten your login form security from shady visitors.. Considering it’s possible to know which field entered the correct information, then all they need to do is to continue guessing the rest.

So, it’s time you might need to know ways to customize error messages for your admin login form. We’ll show you 2 easy ways to display custom error messages using either a custom code snippet or plugin.

Customize Error Messages by Custom Codes

Simply add the following code snippet to your theme’s functions.php file.

function no_wordpress_errors(){
  return 'Something is wrong!';
add_filter( 'login_errors', 'no_wordpress_errors' );

Correspondingly, the same “Something is wrong!” error message will display regardless of whether you entered the incorrect username, password, or both.

Of course, you can change the error message to whatever you want. Simply replace “Something is wrong!” text in custom code with your custom message.

Customize Error Messages Using LoginPress Plugin

If you want to have more control over the error messages, using a plugin is a wise choice. In this tutorial, let’s demonstrate the LoginPress plugin, which can be easily found and installed for free in the WordPress plugin directory.

Let’s get started!

Once installed and activated, navigate to LoginPress > Customizer.

A new screen displays where you can see a lot of customization options. In this tutorial, we’ll focus on the Error Message section.

In this section, you can edit any error messages for specific cases. For example:

  • Incorrect username
  • Incorrect password
  • Empty username
  • Empty password
  • Invalid email

Once you customize the WordPress login error messages, click the “Publish” button on the top left. This will save your changes, which will be live immediately.

Click the “X” icon on the top left corner to close the Customizer.

Let’s say we changed the error message from the default one to a new one as below.

Accordingly, when you try to type in either the wrong username or password, the error message simply states “Something is wrong.”

In addition, you can make use of Custom Login Page Customizer|LoginPress Plugin to:

  • Customize logo
  • Customize background
  • Customize login form
  • Customize forget form
  • Customize reCaptcha
  • Customize welcome message

How Custom Error Messages in Password-Protected Content Form

We’ve gone through how to manage error messages in the admin login form. Now, let’s jump to the next section where you can get a complete guide in error message customization for password-protected content form.

Customize Error Messages in Single Password Forms

If you’re protecting your single posts in WordPress by password forms and want to customize the error messages, you shouldn’t miss out on this section.

First of all, you might need to protect your content with Password Protect WordPress (PPWP) plugin, either Lite or Pro version. After that, you can utilize WordPress Customizer to customize error messages.

Let’s get started!

Navigate to Appearance > Customize.

A new screen display. Scroll down to choose PPWP Single Password Form > Error Message.

By default, the value is “Please enter the correct password.” Here, you can change the message to whatever you want.

Don’t forget to hit the Publish button to make all your changes valid.

Let’s say we’ve changed the message to “Invalid password.”

Consequently, when someone input an incorrect password, the error message will display as an image below.

It’s easy to handle, isn’t it?

What more, with the PPWP plugin and WordPress Customizer, you can change not only the text but font size, font weight, text color and background color.

Customize Expired Password Error Messages

We’ve provided clear instructions on how to display error messages for all incorrect passwords, regardless it’s an invalid or expired one.

In case you want to customize expired password error messages, you might need to use our PPWP Pro plugin, PPWP Suite extension along with WordPress Customizer.

Once you install and activate the plugins in your admin dashboard, head over to  Password Protect WordPress > Advanced.

Simply enable the “Customize Expired Password Message” option.

By default, when users enter an expired password, they will receive the following message.

You can change this message yourself with WordPress Customizer.

  1. Go to Appearance > Customize from your WordPress dashboard.
  2. In the left sidebar, choose Password Protect WordPress Form > Error Message.

  3. Scroll down to the bottom of this section to see the expired password message.
  4. Input your desired message then hit Publish.

Let’s say we’ve changed the text to “Please enter an active password!”

Now, if anyone accesses your protected content with an expired password, they will receive the message.

Now You Know How to Display Custom Error Messages in WordPress

Our article has guided you on how to display custom error messages in WordPress. If you intend to customize an error message in your admin login page, the provided custom code or LoginPress plugin will give you a hand.

In case you need to create error messages yourself for password protected content form, PPWP plugin and WordPress Customizer are the best choices.

To customize error messages at a higher level, considering PPWP Pro and PPWP Suite to inform your user of expired passwords.

Displaying your custom error messages in WordPress is no more a tough nut to crack provided that you get our tutorial in the right way.

Have you managed to customize the error messages using our guide? Let us know if in the comments box below.