Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a drop down menu which contains my custom login box...

<form name="loginform" id="loginform" action="<?php echo bloginfo('url') ?>/wp-login.php" method="post">
    <p class="login-username">
        <input placeholder="email address" type="text" style="text-align:right;" name="log" id="user_login" class="input" value="" size="20" />
    </p>
    <p class="login-password">
        <input placeholder="password" type="password" style="text-align:right;" name="pwd" id="user_pass" class="input" value="" size="20" />
    </p>
    <input type="submit" name="wp-submit" id="wp-submit" value="Login" /><input type="hidden" name="redirect_to" value="<?php $_SERVER['REQUEST_URI']; ?>" />
</form>

This works great, what happens if somebody either enters nothing in the boxes and presses submit or enters incorrect detail is they are taken to a custom login page at www.mydomain.com/login

This is all good but what I need to do is give the user some indication of why they have landed on this page, a message box saying 'Incorrect details please try again'

Anyone any ideas how I would go about it?

share|improve this question

2 Answers 2

You have a number of options at your disposal.

Two of which could be;

1) Stop the user from being re-directed to /login and use jQuery to alert the user that their login information is incorrect on the page in which the details were entered.

2) You could have them re-directed to the /login page and edit the /wp-login.php file to add a block of HTML (which will tell the user they entered their details incorrectly) and style it with CSS.

share|improve this answer

Simply use a hidden field in your custom login form:

<input type="hidden" name="custom-login" value="1" />

And hook into the wp-login form (head, footer or the form itself):

add_action( 'login_head', 'failed_login_message', 10, 0 ); // display message at top of page
// add_action( 'login_footer', 'failed_login_message', 10, 0 ); // display at bottom of page
// add_action( ''login_form_login', 'failed_login_message', 10, 0 ); // display message WITHIN the form

function failed_login_message() {
  // bail if the user does not come from the custom login form
  if ( ! isset( $_POST['custom-login'] ) || true != $_POST['custom-login'] )
    return false;

  echo '<p class="error">Something went wrong. Your login data wasn\'t correct. Try again.</p>';

  return true;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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