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...


<div class="container">
  <div class="row">
    <div class="col-md-4 offset-md-4">
<div class="card">
  <div class="card-header text-center">
  <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 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 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>
  <?php wp_nonce_field( 'user_log_action', 'user_log_nonce_field' ); ?>
  <button type="submit" class="btn btn-success" name="submit_login">Login</button>
  <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>


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' );

1 Answer 1


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

  • No this code is not useful
    – Minesh
    Jun 6, 2019 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.