Skip to content

dart-creations.com

Advertisement
Home arrow Forums
Print E-mail

#71 - Hide a menu item when user logs in

There 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:

<?php
$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
Comments
Search RSS
wexplorer18  - where do I have to add the code?   |79.31.198.xxx |2009-09-16 11:40:14
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
joestange   |68.104.178.xxx |2009-11-19 10:19:45
Your code breaks the site. It gives a parse error. I have tried it on 4 sites.
DART   |217.145.5.xxx |2009-11-19 11:34:32
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.
magicflyer  - re:   |71.153.26.xxx |2009-12-28 17:15:34
joestange wrote:
Your code breaks the site. It gives a parse error. I have tried it on 4
sites.


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!
rad02  - re:   |213.107.131.xxx |2009-12-02 14:14:57
DART wrote:
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

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
rleathers  - MetaMod   |75.64.200.xxx |2010-01-30 20:31:14
I know this is late but when you want to hide anything based on user role,
logged in status, geo location, etc. try
MetaMod.
nolinkspls://zzz.metamodpro.com/
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Buy us a beer!

If we've helped you, consider buying a beer €3. It will inspire us to keep on giving! Cheers!

Sponsors

Login Form






Lost Password?
No account yet? Register

Pagerank
Generated in 0.26318 Seconds