I have made a login form on the front-end of my site using wp_login_form(). However, when the user types in an incorrect username/password they are redirected to the wp-admin login form.

How can you instead display any error messages above the login form? Ideally, I don't want the user to ever have to see the Wordpress admin section.

I have tried using the redirect_invalid_login() hook but this doesn't seem to work?


2 Answers 2


just add the following code to your function.php. it will redirect back user from where the login form is submitted.

add_action( 'wp_login_failed', 'my_front_end_login_fail' );  // hook failed login

function my_front_end_login_fail( $username ) {
   $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
   // if there's a valid referrer, and it's not the default log-in screen
   if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
      wp_redirect( $referrer . '?login=failed' );  // let's append some information (login=failed) to the URL for the theme to use
  • 1
    how can we get errors like invalid passowrd or invalid username etc...???
    – vrajesh
    Commented Jun 26, 2015 at 6:29
  • 3
    The best practice is not to show specific error but instead something like "invalid credentials". Showing "invalid password" means that the user exist on this site so that is one less thing to guess (and by itself knowing that an email is registered on some website can be a privacy issue). If you show "invalid password" then it means some user on this site use this password which is not ideal. And to get the info that there was an error you can check if $_GET['login'] == 'failed'.
    – idFlood
    Commented Nov 30, 2018 at 16:05
  • I'm not a fan of function.php/theme.php but this worked. Maybe I want to add a php snippet to my header file template in elementor but no one does that. Commented Sep 14, 2023 at 0:09

you know that fixes it but it still screws up when you dont enter in any info.

I really don't like using functions.php.

I'd like to to like index.php but things like that really haven't been possible for some reason. There needs to be a better solution.

The "essentials addons" login form for elementor seems to fix the all problems if you're using elementor. That's the only thing I can find that really gets the job done. Good thing its free.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.