DART Creations

#3 - Hiding a menu or module once a user is logged in

PDF Print E-mail

#3 - Hiding a menu or module positions once a user is logged in

Have you ever wanted to hide one of your menus or module / module positions if your users have logged on? The following small template hack will hide your menu once your user has logged on.

 

The idea behind this is to actually load a particular position (the menu position) only if the user has not logged in:

Joomla 1.5 and Joomla 2.5

$user =& JFactory::getUser();

$user_id = $user->get('id');

This returns the user id of the user.  Therefore the code to do this is check whether the current user has a valid id (i.e. they are logged), if not load the module:

<?php   
  $user =& JFactory::getUser();   
  $user_id = $user->get('id');   
  if (!$user_id)   
  {   
  ?>       
    <jdoc:include type="modules" name="left" />
  <?php
  }

?> 

Joomla 1.0 

if( !$my->id )mosLoadModules ( 'left' );

and should be placed in the index.php of the template you are using (/templates/<yourtemplate>/index.php). The code will hide all modules which are assigned to the left position. If you only want to hide your menu item, you should create an additional position in your template (e.g. hidingmenu), assign your hideable menu to this position and then hide that position only.

if( !$my->id )mosLoadModules ( 'hidingmenu' );

 

 
 
Comments (9)
Only registered users can write comments!
  • Marcio Martins  - Hide Modules

    Hello.. I want to hide some modules when a registered user log in into the site. In wich files I have to do this hack? I´m using joomla1.5

    email: desimarcio@gmail.com

    very thanks

  • DART Creations  - Hide modules

    Mancio,

    best thing to do is to create a position in your template (check out the tutorial on this site) and then hide it using the above technique when a user logs in. You'll only have to hack your template.

  • Christian Sweningsen  - Confused re 1.0 & 1.5

    Hi, Many thanks for very good tutorials, on good topics!

    In this one, I'm not clear which parts of the instructions go with J1.5; only the part with that label; or (as it looks to me) also some of the 1.0?

    thanks,
    Christian

  • Chrille  - Great!

    Just what I was looking for, thanks!

  • truongson.bkap

    I want hidden list module manager. When login by supper administrator don't show list module manager. I don't know hack code file ??? in folder???. please help me.

  • Kroc

    Great Post. I have one small issue, I used the right position as the one that is only visible to guests. The menus in the right position are indeed hidden, but the space is still being used as if the menu was there, just hidden. I am running Joomla 1.5.

    Thoughts? Thanks

  • DART  - Empty space

    The space is defined by the HTML elements of your template, you'll have to insert the code in the appropriate places such that those elements "collapse" when there are no menus being displayed.

  • Federico  - Voila, it works!

    Great help in just a few lines of code!
    Created a new position in my template, added some lines to the it and its xml and everything worked just fine!
    30 minutes and I got finally rid of the Login module once logged in.
    Cool guides! Keep up with them!

  • Veronika

    Is it possible to use this code (altered)to show an additional menu to two groups of users? Like Group A would see a menu A, Group B would see a menu B in addition to all other menus?

    Veronika

Resources

Translate

English French German Italian Portuguese Russian Spanish