Skip to content

Instantly share code, notes, and snippets.

@alokstha1
Created July 7, 2016 16:14
Show Gist options
  • Save alokstha1/965fbd12cc6ae411805efeba7024e61b to your computer and use it in GitHub Desktop.
Save alokstha1/965fbd12cc6ae411805efeba7024e61b 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