title: Return wordpress user to original page after they register
body: <p>I'm working on a Wordpress site which has various features that are only available to registered users. I need to prompt the users to register/login at various places, and after they do I want to return them to the original page they were on. </p>
  
  <p>I know how to do this manually, but my suspicion is that there is a way to take advantage of built-in Wordpress functions, so I'd rather not "reinvent the wheel." I've searched for solutions but I've only found strategies that involve a hard-coded, static return page after registration. I DON'T want to do this. I'm looking for a way to keep track of the referring page, and return to it after registration. Thanks in advance.</p>
  
  <p>EDIT1: I've located what I thought I was looking for, which is the filter hook <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect" rel="nofollow">login_redirect</a>. It appears to be designed for exactly what I want to do, but I don't seem to be able to get it to work.</p>
  
  <p>The implementation should be pretty straight-forward, so I'm not sure what I could be doing wrong. Here's the code in my theme's functions.php:</p>
  
  <pre><code>function redirect_to_function($redirect_to, $request, $user)
  {
  return 'http://www.mywebsite.com/redirect_page/';
  
  }
  add_filter( 'login_redirect', 'redirect_to_function', 10, 3 );
  </code></pre>
  
  <p>EDIT2:
  I think I solved the mystery as to why the redirect_to filter isn't working, as well as the solution using the hidden field named "redirect_to" (see comments below). I'm using the s2Member plugin to manage membership levels, and I suspect that it is overriding the built-in wordpress functionality.</p>