I can get the title of the active menu using

$menu = &Jsite::getMenu();
$menuname = $menu->getActive()->title;

But how can I access it's parent title?

3 Answers 3


Try this code:

$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title

If you need the link

$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );
  • While this answer is correct, you should check the return value of getActive() because there maybe is no active menu and you get a non-object back (I think null) Commented Apr 22, 2014 at 18:24

The method getActive return a object with the active menu properties including the parent_id. The JMenu class has a method getItem($id), where $id is a menu id. This method return the same type of object that getActive. So, you can do something like this:

$menu = JFactory::getApplication()->getMenu();
$parent_id = $menu->getActive()->parent_id;
$parent_title = $menu->getItem($parent_id)->title;

Since you can get the active menu, you can get the rest by getting the tree. This is usefull to traverse the item list, not just the parent!

So that you understand better, I'm spliting the answer in parts:

1. Create a variable for the active menu (for simplicity and portability):

$menu = &JSite::getMenu();
$active = $menu->getActive();

2. Pick the previous/parent menu by getting the previous item in the tree:

$parent_item_id = $active->tree[count($active->tree) - 2];

NOTE: the tree is an array, and starts with zero, that's why I am subtracting by 2.

3. Finally get the menu title:


Mind you that you also need to add some checks to see if there is an active menu, and/or other error checks.

  • You shouldn't use $menu = &JSite::getMenu();, because it is not a static function. The correct way is to use the code as specified by @me7hos. Commented Apr 22, 2014 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.