How to create a Menu based a username

How would I create a menu so lets say user1 sees user1‘s menu and not user2. Or just see their own pages which I assigned to them in a menu.

So not user role menu but a username menu.

Related posts

Leave a Reply

1 comment

  1. As said in the comments, this depends on how many users there are and how different those menus are supposed to be.

    If there are just a few users and you want completely different menus for each of them, you would have to create different menus in the backend and the call them conditionally in your theme template like this:

    $current_user = wp_get_current_user();
    if ($current_user->user_login == 'john') (wp_nav_menu(array('theme_location'=>'johnsmenu')))
    elseif ....
    

    If there are many users and you want to include systematic information, such as a link to their author archive or information from their profile, your best bet may be to define no menu at all and let the menu be generated by a fallback function. So you would have:

    wp_nav_menu (array ('fallback_cb'=>'wpse69315_fallback', ...));
    

    In the fallback you can generate your own structure of <li> elements and include, for instance, links to www.example.com/author/ . $current_user->user_login .