WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I create 2 custom navigation menu for logged in and logged out users? (4 posts)

  1. adnan0777
    Member
    Posted 1 year ago #

    What I am looking for are two different menu for logged in and logged out users in the main menu navigation area. I have created the 2 menus named menu_0(for logged in users) and menu_1 for(logged out users). I am so close getting there but got stuck. So I am looking for some help.

    I have modified the code of header.php of my theme file from line 304 to line 317 . By default it looks like this:

    <div id="navigation">
     <?php if ( function_exists( 'wp_nav_menu' ) ) { // Added in 3.0 ?>
     <ul id="nav">
     <?php echo bp_wp_custom_nav_menu($get_custom_locati… $get_default_menu='revert_wp_menu_page')… ?>
     </ul>
     <?php } else { ?>
     <ul id="nav">
     <li<?php if(is_front_page()) { echo " id='home'"; } ?>><a href="<?php echo home_url(); ?>" title="<?php _e('Go back to home', TEMPLATE_DOMAIN); ?>"><?php _e('Home', TEMPLATE_DOMAIN); ?></a></li>
     <?php wp_list_pages('title_li=&depth=0'); ?>
     </ul>
     <?php } ?>

    I modified the code to this custom structure:

    div id="navigation">
     <?php if ( function_exists( 'wp_nav_menu' ) ) { // Added in 3.0 ?>
     <ul id="nav">
     <?php if ( is_user_logged_in() ) : ?>
     //**suggest your code here **//
     <?php else : ?>
     //**suggest your code here**//
     <?php endif; ?>
     </ul>
     <?php } else { ?>
     <ul id="nav">
     <li<?php if(is_front_page()) { echo " id='home'"; } ?>><a href="<?php echo home_url(); ?>" title="<?php _e('Go back to home', TEMPLATE_DOMAIN); ?>"><?php _e('Home', TEMPLATE_DOMAIN); ?></a></li>
     <?php wp_list_pages('title_li=&depth=0'); ?>
     </ul>
     <?php } ?>
    
     </div>

    The custom structure works; I have verified that but I just need appropriate code to fill those gaps.

    It would be a very simple for those people who knows PHP. I don't know however.

    For reference see this pastebin of header.php file:

    http://pastebin.com/ktMtBpsP

    Some might also recommend adding or modifying some custom function in functions.php but I prefer the mentioned way because the functiosn.php file of my theme is so big, I will loose track.
    But I am giving the link of functions.php for any reference:

    http://pastebin.com/P0wL4YB8

    I have found a similar problem as mine in the wordpress forum but with different theme. This could lead you to right direction to answer my question:

    http://wordpress.org/support/topic/alternative-menu-for-logged-in-users?replies=12

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Have you reviewed this Codex section?

  3. adnan0777
    Member
    Posted 1 year ago #

    I have got a plug in called 'Nav Menu Roles' which shows or hide specific menu items based on user role. It basically does the same but within the same menu. Keeping the thread open for some more responses and alternative suggestions.

  4. adnan0777
    Member
    Posted 1 year ago #

    I am using 'Nav Menu Roles' plug in for quite some time. And its awesome. I think I will stick with this plug in unless I master the codes.

Topic Closed

This topic has been closed to new replies.

About this Topic