Home / admin / Redirect failed login attempts to any location
  • How to Redirect failed login attempts to any location

    redirect-failed-login-attempts-to-any-location

    Adding this snippet to the functions.php or your wordpress theme will allow you to redirect failed login attempts to any location.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    add_action( 'wp_login_failed', 'my_front_end_login_fail' );
    function my_front_end_login_fail( $username ) {
         $referrer = $_SERVER['HTTP_REFERER'];
         if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
              wp_redirect( $referrer . '?login=failed' );
              exit;
         }
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    wp_redirect, add_action, _e, wp,