Joomla - Getting the Default Menu Link Print

  • 0

The following example shows how to use the getMenu() class to pull the default menu item.  We build the valid url by appending the ever so elusive "Itemid" to the query.  If your website does not need to track the menu item then you can simply pull the $defaultMenu->link value.

/***************************************************
 * Pull the Default Menu item and Build the URL
 ***************************************************/
$defaultMenu = JFactory::getApplication()->getMenu()->getDefault();
$defaultMenuUrl = 'index.php?'.http_build_query(array_merge($defaultMenu->query,array('Itemid'=>$defaultMenu->id)));
$defaultMenuLink = JRoute::_($defaultMenuUrl);
$defaultMenuReturn = base64_encode($defaultMenuLink);

Was this answer helpful?

« Back