#71 - Hide a menu item when user logs in | ![]() | ![]() | ![]() |
#71 - Hide a menu item when user logs inThere are times when you need to hide specific menu items when a user has logged on to your Joomla website. This cannot be done using standard functionality, we the following is a simple workaround to allow you to cheat by hiding the menu item when a user logs in. If you want to hide a whole module eg the menu you can used the trick here: #3 - Hiding a menu once logged in So what do we do to hide the menu item for logged in users? A combination of using the Joomla framework (getUser) and a CSS trick (display:none) to hide items. In your template place the following code: $user =& JFactory::getUser(); if( !$user->guest ) ?> <style type="text/css"> .item10 { display:none; } </style> <?php endif; ?> replace the 10 in .item10 with the id of the menu item.NOTE: this only works on the menu if the menu's module is set to 'List'. If you are familiar with CSS you can use it / extend for the style of any menu item you choose
|
Your code breaks the site. It gives a parse error. I have tried it on 4 sites.
Well, i've tested it and it works. Unfotunately, templates are typically so different from each other, that what works on one, does not necessarily work on another. The code here basically gives you a hint on the direction you need to take when trying to do this.
I got the parse error as well... changed the line:
if( !$user->guest ) ?>
to
if( !$user->guest ) : ?>
and this worked like a champ. Thanks DART!
Can you please give an indication how the code can modified for usage with the following Menu Styles
?
Legacy - Vertical
Legacy - Horizontal
Legacy - Flat List
Thanks ![]()


Hello,
thank you very much for your tip
That's exacly what I was looking for
for the Log-in menu item of the
restricted area.
where do I have to add the peace of code above? I tryed it at different positions
in the file index.php with no success
Thank you, regards