How do I hide one menu item link for logged in and logged out users

Using bbPress and s2Member, I need to hide the registration link in the menu for logged in users and the members directory link for non logged in users.

Related posts

Leave a Reply

1 comment

  1. A simple way to achieve that is to create two separate Navigation Menus (/wp-admin/nav-menus.php), and in your theme use the following:

    // Reference:
    // http://codex.wordpress.org/Function_Reference/is_user_logged_in
    // http://codex.wordpress.org/Function_Reference/wp_nav_menu
    
    if( is_user_logged_in() ) {
        wp_nav_menu( array( 'theme_location' => 'logged-users' ) );
    } else {
        wp_nav_menu( array( 'theme_location' => 'not-logged-users' ) );
    }
    

    Instead of theme_location, you can use the menu name directly, check the documentation for wp_nav_menu.
    And you’d probably would like to use the function is_user_logged_in in the template files for the Registration and Directory pages.