[resolved] Menu items to appear only if user is logged id (3 posts)

  1. joand
    Posted 8 years ago #

    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?

  2. Kafkaesqui

    Posted 8 years ago #

    You just need to test on the global variable $user_login:

    global $user_login;
    if( $user_login ) :

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

    <?php endif; ?>

  3. joand
    Posted 8 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic