0

I have a number of pages that are only viewable to users who are NOT logged in. I have a widget that allows users to sign in.

I am trying to find a way for users who sign in whilst on these particular pages to be redirected to my homepage. Any users who sign in on any other pages will remain on that page.

I assume the code will need to be the following:

Has user logged in
     is current page A or B or C
         if yes, redirect to homepage
     else
          redirect to current page
0

Use this:

if ( is_user_logged_in () ) {
    if ( is_page ( 'A' ) || is_page ( 'B' ) || is_page ( 'C' ) ) {   
        wp_safe_redirect( home_url() ); 
    }   
    // If we don't redirect, then will be in current page. No need to reload this page again. 
}
2
  • @Gabriel sorry no such luck. :( i can still visit the pages when logged in. – user3290060 Nov 25 '15 at 18:26
  • It will work properly. Please copy paste the real code which you applied there. Let me tell you. – Kvvaradha Nov 26 '15 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.