Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As stated in the following:

http://wordpress.stackexchange.com/a/100573/16266

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
1  
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

1 Answer 1

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"] );
      wp_redirect($url);
   exit;
 }}
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

 
discard

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.