Different Menu for Members and Guests

Discussion in 'Templates customization' started by wikaeaaccount, Oct 10, 2014.

  1. wikaeaaccount

    wikaeaaccount aMember Pro Customer

    Joined:
    Jan 15, 2014
    Messages:
    9
    Hello,

    I hope someone can help me. I am using Wordpress and aMember Pro to protect my pages.

    I want certain pages, like the sign up page, to be hidden from the menu for users who have logged in and have purchased a membership level. For me it does not make sense to show a signup page to a user that already bought your service. I am a bit surprised that this is not a functionality included in aMember.

    I tried to set the page as "Show page only for guests Page will be displayed only when user is not logged in", but that only gives the user a 404 if they click on the page.

    Is there any way to use one Wordpress menu for guests and another for members? Can I somehow customize something to make this happen?

    I am doing it the other way around. I mean, I have certain pages that are protected in the menu, but they do not appear unless the user is logged in, which makes sense.

    Anyone had this same issue?
  2. wikaeaaccount

    wikaeaaccount aMember Pro Customer

    Joined:
    Jan 15, 2014
    Messages:
    9
    I have not found a solution, but thought I should post an update in case someone else is struggling with the same issue. I have been experimenting a bit more and at least I can get rid of the menu items that only members should see. You just enable protection for that page and make sure that you have checked Exclude Post for guests under "Menu Item Protection for Post / Page Link".

    Another useful thing is that I can enable protection for the root menu item and then all child pages under that menu item are also removed. For me that was very useful. I have a Members menu item. Under that I have a custom link to amember logout page for example. If you are not logged in, you don't need to logout! However, Wordpress does not allow me to set protection for a custom link, so when I protection for the page linked with the members menu item, all of them disappear!

    Still hoping there is a way to stop logged in users from seeing the "Login" menu item. That just looks strange, but I think I can live with this solution. It would just be great if it was possible to remove things from the menu for members, but I can live with it :)
  3. wikaeaaccount

    wikaeaaccount aMember Pro Customer

    Joined:
    Jan 15, 2014
    Messages:
    9
    Solved! :)

    It is actually a wordpress issue and not really related to aMember. All you have to do is create two menus, one called loggedin and the other one loggedout. You then edit the functions.php of your theme and add the following:

    PHP:
    function my_wp_nav_menu_args$args '' ) {

    if( 
    is_user_logged_in() ) {
        
    $args['menu'] = 'loggedin';
    } else {
        
    $args['menu'] = 'loggedout';
    }
        return 
    $args;
    }
    add_filter'wp_nav_menu_args''my_wp_nav_menu_args' );
    aliceboll likes this.

Share This Page