WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Menu items to appear only if user is logged id

[Resolved] Menu items to appear only if user is logged id

  • I have created a couple of pages that I would like to show up in a separate menu only if the user is logged in. I tried searching but couldn’t find anything (then again I am not entirely sure what to search for) I have excluded those pages from my main page menu, i.e. <?php wp_list_pages('exclude=8,12'); ?>

    Is is possible to have a second wp_list_pages this time including 8 and 12, but wrapped with an if statement? In English, what I want is “if the user is logged in, then show links to pages 8 and 12, otherwise, show nothing.” If so, what would that if statement look like in PHP?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You just need to test on the global variable $user_login:

    <?php
    global $user_login;
    if( $user_login ) :
    ?>

    <?php wp_list_pages('include=8,12'); ?>

    <?php endif; ?>

    It is a beautiful thing!! I knew it would be easy for someone who knew what they were doing (and pretty much impossible for me!)

    Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Menu items to appear only if user is logged id’ is closed to new replies.