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

#3 - Hiding a menu or module positions once you check if 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 - check if a user is logged in

(1.5, 2.5 and 3.x)

$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' );

 

 


Translate

This site is proudly hosted on FAST GoGeek SiteGround servers and given an insane speed thanks to MaxCDN!

Web Hosting MAxCDN - Speed up your website

Friends

Advertise on DART-Creations.com

DART Creations is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

49 fonts for $29

49 fonts plus 17 FREE bonus fonts as well. Over 95% discount - September Only! The Huge September Font Bundle

Website Templates and Themes From $3

You'll surely find your perfect website theme here. Wordpress, Joomla or whatever else you may need.

Theme Forest

 

ced25556c6547d0c287a4a5bcdfc9aa164144c70