How to redirect user to Referrer Page using wp_signon in Custom Login Page in WordPress

I have created a Custom Login Page using wp_signon in WordPress. The code is working fine. The only issue is I am not ge

I have created a Custom Login Page using wp_signon in WordPress. The code is working fine. The only issue is I am not getting as to how I redirect user back to the Referrer Page after login.

Following is my code...

page-login.php

<div class="container">
  <div class="row">
    <div class="col-md-4 offset-md-4">
<div class="card">
  <div class="card-header text-center">
    <b>Login</b>
  </div>
  <div class="card-body">

<form method="POST">
  <div class="form-group">
    <label for="user_name"><strong>Username or Email Address <font color="red">*</font></strong></label>
    <input type="text" class="form-control" name="user_name" id="user_name" placeholder="Enter email">
  </div>
  <div class="form-group">
    <label for="password"><strong>Password <font color="red">*</font></strong></label>
    <input type="password" class="form-control" name="password" id="password" placeholder="Password">
  </div>
  <div class="form-group form-check">
    <input type="checkbox" class="form-check-input" name="remember" id="remember" checked>
    <label class="form-check-label" for="remember">Remember Me</label>
  </div>
  <?php wp_nonce_field( 'user_log_action', 'user_log_nonce_field' ); ?>
  <button type="submit" class="btn btn-success" name="submit_login">Login</button>
</form>
  </div>
  <div class="card-footer text-muted text-center">
    <a href="<?php echo site_url('lost-password'); ?>" class="text-muted">Forgot your Password?</a> | <a href="<?php echo site_url('/register'); ?>" class="text-muted">Register</a>
  </div>
</div>
    </div>
  </div>
</div>

functions.php

function custom_login() {

if ( isset( $_POST['submit_login'] ) ) {

    $user_name = $_POST[ 'user_name' ];
    $password = $_POST[ 'password' ];
    $remember = $_POST['remember'];

    $creds['user_login'] = $username;
    $creds['user_password'] = $password;
    $creds['remember'] = $remember;

    $user = wp_signon( $creds, false );

}
// run it before the headers and cookies are sent
add_action( 'init', 'custom_login' );

I have created a Custom Login Page using wp_signon in WordPress. The code is working fine. The only issue is I am not getting as to how I redirect user back to the Referrer Page after login.

Following is my code...

page-login.php

<div class="container">
  <div class="row">
    <div class="col-md-4 offset-md-4">
<div class="card">
  <div class="card-header text-center">
    <b>Login</b>
  </div>
  <div class="card-body">

<form method="POST">
  <div class="form-group">
    <label for="user_name"><strong>Username or Email Address <font color="red">*</font></strong></label>
    <input type="text" class="form-control" name="user_name" id="user_name" placeholder="Enter email">
  </div>
  <div class="form-group">
    <label for="password"><strong>Password <font color="red">*</font></strong></label>
    <input type="password" class="form-control" name="password" id="password" placeholder="Password">
  </div>
  <div class="form-group form-check">
    <input type="checkbox" class="form-check-input" name="remember" id="remember" checked>
    <label class="form-check-label" for="remember">Remember Me</label>
  </div>
  <?php wp_nonce_field( 'user_log_action', 'user_log_nonce_field' ); ?>
  <button type="submit" class="btn btn-success" name="submit_login">Login</button>
</form>
  </div>
  <div class="card-footer text-muted text-center">
    <a href="<?php echo site_url('lost-password'); ?>" class="text-muted">Forgot your Password?</a> | <a href="<?php echo site_url('/register'); ?>" class="text-muted">Register</a>
  </div>
</div>
    </div>
  </div>
</div>

functions.php

function custom_login() {

if ( isset( $_POST['submit_login'] ) ) {

    $user_name = $_POST[ 'user_name' ];
    $password = $_POST[ 'password' ];
    $remember = $_POST['remember'];

    $creds['user_login'] = $username;
    $creds['user_password'] = $password;
    $creds['remember'] = $remember;

    $user = wp_signon( $creds, false );

}
// run it before the headers and cookies are sent
add_action( 'init', 'custom_login' );
Share Improve this question asked Jun 6, 2019 at 4:41 MineshMinesh 3173 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I did a quick search. Does this help? It talk about adding a code to your themes functions.php file. https://www.isitwp/redirect-back-to-referring-page-after-login/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433098a4627483.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信