WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Return to requested page after login (6 posts)

  1. lampromy
    Member
    Posted 5 years ago #

    Code below will take you automatically to the wordpress login page and after successful login its will be back to the requested page. You just need to keep this code top of the page.

    if(!function_exists(is_user_logged_in)){
      	  die('Sorry, You do not have access of this page.');
      }
      if ( !is_user_logged_in() ) {
    	$returnPath = get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']);
    	echo "<script type='text/javascript'>";
    	echo "window.location.href='$returnPath'";
    	echo "</script>";
    	exit();
      }
  2. brockangelo
    Member
    Posted 4 years ago #

    Where do you insert this code?

  3. rexolio
    Member
    Posted 4 years ago #

    bump!

    Where do you insert the code?

  4. brockangelo
    Member
    Posted 4 years ago #

    I tried this on wp-login.php and it looped indefinitely to wp-login.php.

  5. rexolio
    Member
    Posted 4 years ago #

    brockangelo,

    you may have figured out what to do already, but I found this post at which shows how to handle it very, very simply: http://davidchambersdesign.com/wordpress-login-redirect/

    Works whether you use it as a link or form action.

    Rex

  6. brockangelo
    Member
    Posted 4 years ago #

    I appreciate that link rexolio. I had set this project off to the side, but now it works like a charm!

Topic Closed

This topic has been closed to new replies.

About this Topic