Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created February 25, 2015 07:05
Show Gist options
  • Select an option

  • Save vishalbasnet23/20c891782ec44d672536 to your computer and use it in GitHub Desktop.

Select an option

Save vishalbasnet23/20c891782ec44d672536 to your computer and use it in GitHub Desktop.
Add Parameter to url on unsuccessful login attempt
<?php
add_action( 'wp_login_failed', 'code_login_failed' );
function code_login_failed( $user ) {
// check what page the login attempt is coming from
$referrer = $_SERVER['HTTP_REFERER'];
// check that were not on the default login page
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') && $user!=null ) {
// make sure we don't already have a failed login attempt
if ( !strstr($referrer, '?login=failed' )) {
// Redirect to the login page and append a querystring of login failed
$new_redirect = add_query_arg( 'login', 'failed', $referrer );
wp_redirect( $new_redirect );
} else {
wp_redirect( $referrer );
}
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment