0

I have two phases to my site, the first is menu, i want my site to hide (normal) menu items if the user isn't logged in e.g when someone visit my site, the menu should be

  • Home
  • About us
  • Products
  • Portfolio
  • Contact

But when someone is logged in, the same menu has

  • Home
  • About us
  • Products
  • Portfolio
  • Contact
  • My account
  • My setting
  • My personal details

Is that something possible, if so how? what should i be reading and know as i want to dive into making custom dashboard with same menu.

1 Answer 1

0

There are at least two ways you can accomplish this:

1. Easy way: simply create two nav menus, one for logged in users, and one for logged out users. Then wherever your theme uses wp_nav_menu() you would simply wrap that output in a conditional to check whether the user is logged in/out and output the appropriate nav menu. The advantage of this is that it's probably the quickest and most developer friendly approach to setup. The disadvantage is that your admins will be stuck maintaining multiple separate nav menus and, for example, if they decide to change "About Us" to just "About" they need to remember to change the item in both menus.

2. Thorough way: create a custom nav walker in conjunction with either a menu item's CSS classes or its Link Relationship. The CSS class or Link Relationship (rel attribute) could be something like logged-in or logged-out and the walker would check for those attributes and perform a check to determine whether the item should be output. The advantage of this is that it only requires one nav menu to maintain. The disadvantages are that it takes slightly longer to setup and you may need to document how the CSS class or Link Relationships work for your client/admin should they need to adjust nav menu items in the future.

1
  • while your example sound something i can use to work with, but i wonder if it would help me further, because my next step would be to make a custom login page logging users into custom dashboard, in which this menu will help, as the next step would be new to me as its something new.
    – localhost
    Oct 11, 2015 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.