• anithamandalapu

    (@anithamandalapu)


    hi,everybody,i need to implement different menus in my wordpress site.if the user didn’t login to our site at that time i need to display one menu,and when he login to our site i need to show another menu.can it possible here ?.if so, please suggest me

Viewing 3 replies - 1 through 3 (of 3 total)
  • owenphillips

    (@owenphillips)

    I do a similar thing to this on a couple of sites using sidebars, custom menus and widgets.

    Fist you have to register extra sidebars (widget areas) in functions.php

    You can then place those sidebars into the pages where you want them.

    My sidebar.php contains this code

    <?php
    if ( is_user_logged_in() ) {
       if ( is_active_sidebar( 'sidebar-10' ) ) {
       dynamic_sidebar( 'sidebar-10' );
       }
    } else {
       if ( is_active_sidebar( 'sidebar-11' ) ) {
       dynamic_sidebar( 'sidebar-11' );
       }
    }
    ?>

    This displays sidebar 10 for a logged in user and sidebar 11 for a non-logged in user.

    You can then create custom menus for each (if your theme supports this) through Appearance > Menus

    And add menu widgets to the corresponding sidebars to display accordingly to whether a user is logged in or out.

    If you want to change the main menu at the top of the page it should be possible by registering a second menu in functions.php e.g.:

    register_nav_menu( 'top-level', __( 'Logged out menu', 'themename' ) );
    register_nav_menu( 'sub-level-loggedin', __( 'logged in menu', 'themename' ) );

    Then use a variant on the previous code to alter header.php where it calls in the main nav menu:

    if ( is_user_logged_in() ) {
    <?php wp_nav_menu( array( 'theme_location' => 'sub-level-loggedin' ) ); ?>
    } else {
    <?php wp_nav_menu( array( 'theme_location' => 'top-level' ) ); ?>
    }

    I’ve done this on the fly so I haven’t tested it, but I don’t see why it wouldn’t work…!

    Hope this helps…

    Thread Starter anithamandalapu

    (@anithamandalapu)

    @owenphillips
    thank u so much for ur reply,i tried it but i am not sure whether where i need to put this code and how to run it.can u please elaborate the answer .As i am not that much good in coding of wordpress.

    lara400

    (@lara400)

    if ( is_user_logged_in() ) {
    
    // Add the menu code you want to show when the user is logged in
    
    }else{
    
    // Add the menu code you want to show when the user is not logged in
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘displaying different menus when login and logout’ is closed to new replies.