WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. joand
    Member
    Posted 6 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 6 years ago #

    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; ?>

  3. joand
    Member
    Posted 6 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