#71 - Hide a menu item when user logs in

#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 depends on which version of Joomla you are using, in the older versions of Joomla this could not be done using standard functionality, however from Joomla 1.7 onwards there is a very simple way to do this with ACLs. The article below will show both methonds.  

If you want to hide a whole module eg the menu you can used the trick here: #3 - Hiding a menu once logged in

Joomla 1.7 Onwards

The Joomla Access Control functionality allows you to easily set items which should be displayed to guests, but hidden from logged in users. 

If you go to the User Manager options you will see a setting for the default group that registered users are placed, you will also see a default group for guests (non logged in users). The latter group can be used to create a new group at the same level in the ACL tree for guests.

  1. Create a Guest Group in the User Manager
  2. Add a new Guest Viewing Access Level
  3. Change the default guest group in the User Manager options

Assign modules or menu links to the new group

To hide menu items or module, what you will to do is assign any menu link or module to the newly created Guest level and because it is at the same level in the ACL tree as Registered anything assigned to guest will not be visible to registered users.

Pre Joomla 1.7

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; }

<?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




15,000+ Users trust us - Subscribe