Joomla Check if a user is logged in and hiding a menu or module

#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 once you have check that joomla 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' );

 

 

One more thing...

Do you have friends or a Facebook group who you think would find this useful? Share this with them and then let me know what they think.

Want to supercharge your website?

  Our website loads FAST ... just 1.29 seconds. We're hosted on FAST InMotion servers We want YOUR website to be fast too, so we've gotten you an exclusive deal - 47% OFF for DART Creations friends + FREE domain! Check it out NOW!

Translate

who are we?

DART Creations is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites.

David attard

Follow us on Social

         

 

 

 

Popular Content

Joomla extensions to take your website to the NEXT level

Is your Joomla website reaching its full potential? We install many of these extensions on almost ALL of our Joomla sites - why don't you check them out our list of Joomla Extensions and see whether you can take your site to the next level?

Where are we hosted?

This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

Web Hosting MaxCDN - Speed up your website

 

InMotion Hosting Review - Recommended Web Hosting servers for business, Joomla, WordPress and ecommerce websites.

InMotion Hosting Review

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

The August DESIGN Bundle

65 premiums fonts, 13 graphic packs for$29. Get it NOW - August Only!

August bundle

New! DIVI 3.0 WordPress TeMPLATE + PageBuilder - 20% OFF Limited Launch offer

You'll surely create a perfect website with Divi 3.0!

Divi 3