Skip to:
Content
Pages
Categories
Search
Top
Bottom

error message to a custom login page


  • Raval
    Participant

    @ravals

    Hi,
    I am working on the login form on the home page and I use “WordPress Login Form”. To avoid being redirected to login.php after entering the wrong data and when the form fields are empty, I pasted the following code. I have a question, how do I add a login error message to a custom login page „WordPress Login Form”?
    ps. I think the added code does not have to be divided into two parts. Can it be shortened?

    <?php
    //Is the data correct
    function my_front_end_login_fail( $username ) {
       $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
       // 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') ) {
          wp_redirect( $referrer . '?login=failed' );  // let's append some information (login=failed) to the URL for the theme to use
    	  add_action( 'wp_login_failed', 'wp_login_form');
          exit;
       }
    }
    
    //if the fields in the form are empty
    add_action( 'wp_authenticate', '_catch_empty_user', 1, 2 );
    function _catch_empty_user( $username, $pwd ) {
    	$referrer = $_SERVER['HTTP_REFERER'];
      if ( empty( $username ) || empty( $pwd )) {
    	  wp_redirect( $referrer . '?login=failed' );
        exit();
      }
    }
    
    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar