failed to login in wordpress, it should not redirected to wp-login.php

If user failed to login in wordpress, it should not redirected to wp-login.php
how to do I stop that from happening?
thanks.

Dev

  • Alex Stine

    Try this code in your functions.php file.

    / hook failed login
    add_action('wp_login_failed', 'my_front_end_login_fail'); 
    
    function my_front_end_login_fail($username){
        // Get the reffering page, where did the post submission come from?
        $referrer = $_SERVER['HTTP_REFERER'];
    
        // if there's a valid referrer, and it's not the default log-in screen
        if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
            // let's append some information (login=failed) to the URL for the theme to use
            wp_redirect($referrer . '?login=failed');
        exit;
        }
    }

    Good Luck.

  • Predrag Dubajic

    Hey @Private,

    Hope you're doing well today :slight_smile:

    You can try with the code Alex provided above, just note there seems to be typo in first line, so either remove the first line or add another backslash before it so it looks like this:
    // hook failed login

    If that doesn't work could you give us some more info about your setup, are you using plugin for creating front end login sections etc.

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.