Support » Fixing WordPress » Help needed with is_page()

  • For some reason I cannot seem to get the is_page function to work. I am trying to make it so if someone is not logged in when they go to a specific page (not the site as a whole) they will be redirected to go login first. Here is my code:

    if ( !is_user_logged_in( ) && is_page(4) ) {
    wp_redirect( “http://www.sample.com”, 301 );
    exit;
    }

    When I use the if_user_logged_in by itself it works fine, but when I add the is_page() condition it won’t trigger. When I try to use the is_page condition by itself without the logged in function it won’t work either. I have been placing the code at the top of the functions.php file right after the opening php tag and right before the first set of comments. Can someone please help me out and tell me what I’m doing wrong. Am I placing the code in the wrong place perhaps? Thank you in advance 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help needed with is_page()’ is closed to new replies.