Support » Themes and Templates » Hide Page from logged out users

Viewing 7 replies - 1 through 7 (of 7 total)
  • Are you using a WordPress list function to list out your pages or are you listing them manually?

    The easiest way to do it would be to open the page in the page editor, look to the right hand side under “Publish”, and change the “visibility” from public to private.

    I do not believe I am listing them manually. They are listed in the header.php as wp_list_pages. If I change it to private, will people who log into my site be able to see it?

    Yes. People who are logged into WordPress will be able to see it on the front end.

    I set it to private, but that removes it from the menu for everybody, including me. Is there something else I need to do?

    How often do you add/remove pages from the menu? One thing you could do is list them out manually, then wrap the private page in a “is logged in” conditional statement so that only logged in users can view them.

    It would look something like this:

    <?php if (is_user_logged_in()){ echo "<li>link to page url</li>" }; ?>

    Or, you could not alter the lists at all, and just add that to the end of the wp_list_pages tag, before the closing tag. That would list the page there, but just at the very end of the menu.

    Does that make sense?

    Sorry this is late… but it’ll help others I suppose…

    Depending on the theme you’re using and if it applies the “logged-in” class to the body (I believe the default theme does, as does the theme I use, as does the theme used by the author of the hint) you can use the method described here. Works as described and is very easy.

    – Create a child theme to apply a custom style as detailed below, or use a custom style sheet plugin (I use the the Custom Style Plugin, and it does this flawlessly — plugin hasn’t been updated for a while, and the author says it works for wordpress up to 2.9.2, but I am still using it on 3.2.1 with no issues — I’ve been using this plugin for years!)

    – add the following code to that CSS:

    #nav li.logged-in-nav {
    display: none;
    body.logged-in #nav li.logged-in-nav {
    display: list-item;

    – Then on the menu item you create for that page, simply add a css rule for it. ie, there is a box for CSS Classes, add logged-in-nav to that textbox

    For this to work, you’ll need to actually have a primary list defined then edit the actual menu item to find that CSS Classes field.

    Downside, the link is still available in the source code for the page, but unless someone goes looking they wont find it.

    Now, if only someone could tell me how to do exactly the same for users that ARE logged in — ie, I want to hide some pages from logged in users, but there’s no “not-logged-in” or “logged-out” class for the body tag.

    If someone could tell me how to create such a class to that’s added when the page is generated, I’d be stoked!!!

    I forgot to mention in the above code, you must change the #nav to the name of the ID of the unordered list that contains the list/menu items of the relevant menu.

    I have since created a full “how-to-do” on my blog since I was after not only this feature, but another where I only showed menu items to guests and not members–basically the opposite.

    To only show items to logged in users here.

    To show a particular menu item to guests only (something I have been searching for for a while), you can view a more recent post here.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide Page from logged out users’ is closed to new replies.