WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I create a template page as seen below to check if user is logged in or not. If user is not logged in, I want to redirect user to first login page and after login I want him to redirect previous page.

With the code below, Login redirection function redirects to login page again after user login. How can I fix that code?

In my template page :

      wp_redirect( 'http://....../wp-login.php', 302 );
      wp_redirect('----------otherpage---',302 );

in functions.php :

    function directtorequest( $redirect_to, $request, $user )
        // instead of using $redirect_to we're redirecting back to $request
        return $request;
    add_filter('login_redirect', 'directtorequest', 10, 3);
share|improve this question
up vote 0 down vote accepted

Add redirect_to as a query variable in your link whenever you redirect user wp-login.php. Like

wp_redirect('http://...../wp-login.php?redirect_to=your_previous_page_link', 302);

In redirect_to write the link of any page.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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