Title: Login Redirect Query
Last modified: February 7, 2017

---

# Login Redirect Query

 *  Resolved [meglos42](https://wordpress.org/support/users/meglos42/)
 * (@meglos42)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/)
 * Hi,
 * Is it possible to automatically redirect back to the original blocked page after
   logging in via the main Log In page?
    I don’t want to have log in forms on all
   blocked pages/posts, so I just have a link to the log in page. However, I’d like
   the user to be redirected back to the page they came from when they log in. Is
   this possible?
 * Many thanks.

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * (@cbutlerjr)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8781388)
 * The WP-Members login does accept the redirect_to parameter through a query string
   just like the wp-login.php does. So as long as you generate your links with a
   return path, yes it can redirect back to the page they were on. For example:
 * [http://mysite.com/my-login/?redirect_to=http://mysite.com/original-page/](http://mysite.com/my-login/?redirect_to=http://mysite.com/original-page/)
 * There is a redirect function that you could use, [wpmem_redirect_to_login()](http://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_redirect_to_login/)
   which will redirect as well as include the return path.
 *  Thread Starter [meglos42](https://wordpress.org/support/users/meglos42/)
 * (@meglos42)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8798777)
 * Thanks Chad,
 * Using the “?redirect_to=http://mysite.com/original-page/” option works perfectly!
   However I’d like to avoid having to manually set this on every protected page
   as there are a lot of them.
 * I’ve looked at the wpmem_redirect_to_login() but I can’t seem to get it configured
   to work – it doesn’t direct users back to the page they came from, but just stays
   on the Log In page, with the “You are Logged in as xxx” message.
 * Is there any advice you can give me so as I can just use the same [http://mysite.com/my-login](http://mysite.com/my-login)
   link on all the protected pages?
    -  This reply was modified 9 years, 4 months ago by [meglos42](https://wordpress.org/support/users/meglos42/).
    -  This reply was modified 9 years, 4 months ago by [meglos42](https://wordpress.org/support/users/meglos42/).
 *  [airdrummer](https://wordpress.org/support/users/airdrummer/)
 * (@airdrummer)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8799067)
 * perhaps if u gave ur website’s url, we could see just what u r talking about…
   normally, a blocked page says
 * > This content is restricted to site members. If you are an existing member, 
   > please log in. New users may register below.
 * so how do u “just have a link to the log in page.”?
    -  This reply was modified 9 years, 4 months ago by [airdrummer](https://wordpress.org/support/users/airdrummer/).
 *  Plugin Author [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * (@cbutlerjr)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8808103)
 * The wpmem_redirect_to_login() function automatically handles the return redirect.
   You don’t have to configure anything for it. But the way to use this is to redirect
   the user, not use a link to the login page.
 *  Thread Starter [meglos42](https://wordpress.org/support/users/meglos42/)
 * (@meglos42)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8817337)
 * Thanks Chad
 * [@airdrummer](https://wordpress.org/support/users/airdrummer/) – we have code
   on the (unblocked) posts on our home page similar to this –
 * Here is some unblocked content that anyone can read.
    [wpmem_logged_in]and here
   is a bit of protected content hidden from view to everyone that is not logged
   in[/wpmem_logged_in] [wpmem_logged_out]here is a [link](http://mysite.com/my-login)
   to the login page that is only visible to those who are not already logged in[/
   wpmem_logged_out] And here is a bit more unblocked content for everyone.
 * We also have this on several pages thoughout the site with a mixture of blocked
   and unblocked content.
 * So what we want is for people to be able to click that link to log in (a form
   on the post is too much). Once they have logged in we’d like them to be sent 
   back to the page they came from.
 *  [airdrummer](https://wordpress.org/support/users/airdrummer/)
 * (@airdrummer)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8818297)
 * ok hadn’t thot of protecting just bits&pieces of a page, rather than a whole 
   page…perhaps u could add a redirect hook to the referer:
 * `$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';`
 * see [http://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_login_redirect/](http://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_login_redirect/)
    -  This reply was modified 9 years, 4 months ago by [airdrummer](https://wordpress.org/support/users/airdrummer/).
 *  Thread Starter [meglos42](https://wordpress.org/support/users/meglos42/)
 * (@meglos42)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8824820)
 * [@airdrummer](https://wordpress.org/support/users/airdrummer/) – thanks, not 
   sure how to use that (still learning functions etc.) but I’ll see if I can puzzle
   it out.
 *  Plugin Author [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * (@cbutlerjr)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8835909)
 * In your shortcode example, you could use the [wpmem_loginout] shortcode to generate
   a link. It generates a link to log in or out depending on the user’s current 
   state, but since you’re using it within the [wpmem_logged_out] shortcode, it 
   would only be seen when in the logged out state (linking to the login form).
 * The resulting link from this shortcode includes a return path.
 * You can specify specific text for the link with the login_text attribute:
    [wpmem_loginout
   login_text=”Sign In Here”]
 * [http://rocketgeek.com/plugins/wp-members/docs/shortcodes/other-shortcodes/](http://rocketgeek.com/plugins/wp-members/docs/shortcodes/other-shortcodes/)
 * There a two similar shortcodes coming in the 3.1.7 release: [wpmem_login_link]&[
   wpmem_reg_link] – both will include a return path.
 *  Thread Starter [meglos42](https://wordpress.org/support/users/meglos42/)
 * (@meglos42)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8920948)
 * Thanks Chad! You’ve hit the nail on the head – this works perfectly.
    Don’t know
   how I didn’t see this before, your help much appreciated.
    -  This reply was modified 9 years, 3 months ago by [meglos42](https://wordpress.org/support/users/meglos42/).
 *  Plugin Author [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * (@cbutlerjr)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8926685)
 * No problem – glad that worked out.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Login Redirect Query’ is closed to new replies.

 * ![](https://ps.w.org/wp-members/assets/icon-256x256.png?rev=1226414)
 * [WP-Members Membership Plugin](https://wordpress.org/plugins/wp-members/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-members/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-members/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-members/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-members/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-members/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [Chad Butler](https://wordpress.org/support/users/cbutlerjr/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/login-redirect-query/#post-8926685)
 * Status: resolved