Support » Fixing WordPress » Hide page for logged in Users

  • Hi guys,

    I wanna do the following:
    If a user is logged out, he can view the page id=10, if a user is logged in and view page id=10 he will be redirected to page id=5.

    I tried some codes in my theme’s header, but nothing worked. Is there any solution (theme modification in header.php or functions.php – I don’t want to use a plugin for this!) for this on?

    Thank you,
    Michael

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you tried the User Access Manager plug-in?

    Something like this should work:

    if ( is_user_logged_in() && is_page( 10 ) ) {
        wp_redirect( get_permalink( 5 ) );
        exit;
    }

    Edit:
    To make sure it redirects before any headers are sent you would probably want to wrap it in a function and use a hook. I’d put it in functions.php.

    add_action( 'init', 'check_redirect_page' );
    
    function check_redirect_page() {
        if ( is_user_logged_in() && is_page( 10 ) ) {
            wp_redirect( get_permalink( 5 ) );
            exit;
        }
    }

    Big Babel, you’re a genius! This one works like a charm. Thank you very much 🙂

    oshi

    (@thugzanime)

    Hey Big Bagel hoping you can help me out to,

    with mine would be if user is login hide page id 100

    I have two pages one is for login and the other one is for wrong password displaying the message.

    I manage to redirect the user once they login to they profile page, but the wrong password page is available if you type on your browser http://www.mydomainname.com/wrong-password

    it shows for users who are logged in or for guest. so am trying to hide this one page from logged on user and just make it available for guest

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide page for logged in Users’ is closed to new replies.