Magento 2 Version – Magento 2.1.4 CE
I am trying to create Custom Module for Compulsory login.
When user hits the website url it must needs to redirect on login screen and after logged in user can surf or visit our website.
So Compulsory login functionality i have already done by creating custom module.
Here the issue is how to hide menu ? before login(visitors) ?
i want to hide header menu for visitors. once user is logged in then and then menu will show otherwise it needs to be hide.
Hope it clears.
Update :
I know by overriding the topmenu.phtml i can achieve this. but issue here is if i override topmenu.phtml then myaccount,logout links in dropdown are disappear.
Check below screenshot :
Best Answer
Override Magento_Theme::view/frontend/templates/html/topmenu.phtml and use this code in the file:
Though, using objectmanager is not a good practice, so you may override block file too.
to override topmenu.phtml, follow this:
In your module the template needs to be placed here:
Additionally, a layout definition is required:
and put this in default.xml: