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

1 Answer 1

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. Commented Nov 25, 2015 at 18:26
  • It will work properly. Please copy paste the real code which you applied there. Let me tell you.
    – Kvvaradha
    Commented Nov 26, 2015 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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