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

As stated in the following:


I lock the site's contents.

I then click on a post.

I am navigated to wp-login screen.

I enter the correct username + password of admin.

I am never returned back to the article but remain stuck in wp-login without any feedback.

Please help..

share|improve this question
This seems like the same topic as in the thread you mention. Why did you start a new question? – s_ha_dum May 29 '13 at 14:30
See my update in my answer to your former question. Please do not ask the same question again, and do not accept my answer until it is solved. :) – toscho May 29 '13 at 14:57
up vote 1 down vote accepted

You have to edit your redirect function to redirect back to the post where you were before redirection

add_action( 'template_redirect', 'login_to_see_content' );

function login_to_see_content()
  if ( is_singular() && ! is_user_logged_in() )
       auth_redirect(); // does nothing for logged in users

to this

add_action( 'template_redirect', 'login_to_see_content' );
function login_to_see_content(){
   if(is_singular() && ! is_user_logged_in()){
      $url= site_url()."/wp-login.php";
      $url.='?redirect_to="'.urlencode ($_SERVER["REQUEST_URI"] );
share|improve this answer
Thanks this is almost what I needed. Unfortunately, it blocks my home page. I cannot see my homepage without logging in. Help please... Thanks! – p.a. May 30 '13 at 14:49
Try Now . I have corrected this code. – Vikas Bhardwaj May 31 '13 at 4:26
It works! I am very grateful! This was really hard for me, I tried many alternatives. Thank you very much Vikas! – p.a. May 31 '13 at 6:48

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.