WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have chosen to display a login form in the first page of my wordpress website. If the user logs in successfully, he gets redirected to a specific webpage. If he enters a wrong password, he gets redirected to the login page again. The problem happens when someone does not enter username and password: he gets redirected to the wordpress admin login page.

How can I redirect empty username logins back to the main login page ?

this is the code I am using to redirect failed attempts :

add_filter('login_redirect', '_catch_login_error', 10, 3);

function _catch_login_error($redir1, $redir2, $wperr_user)
    if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;

        case 'incorrect_password':
        case 'empty_password':
        case 'invalid_username':
            wp_redirect(home_url()); // modify this as you wish

    return $redir1;
share|improve this question
up vote 6 down vote accepted

Check for an empty user login in the $_REQUEST array:

if ( empty( $_REQUEST['user_login'] ) // && or || empty( $_REQUEST['user_pass'] )
  return $redirect_to_whereever_you_want;

But this filter is to late. It is called after the user is logged in. You have to use the 'wp_authenticate' action, this is one of the earliest action in the login process:

add_action( 'wp_authenticate', '_catch_empty_user', 1, 2 );

function _catch_empty_user( $username, $pwd ) {
  if ( empty( $username ) ) {
    wp_safe_redirect( $redirect_to_whereever_you_want );
share|improve this answer
perfect, perfect, perfect. Thank you. – Radolino Apr 28 '13 at 15:07

Your Answer


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.