PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Basic

Get the Alias of the Active Menu Item

Safely fetches the alias (slug) of the active menu item for CSS hooks, analytics tags or conditional layout logic.

Updated on 24 November 2026 25 copies 110 views
templates/seu_template/index.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$menuItemAlias = (string) (Factory::getApplication()->getMenu()->getActive()?->alias ?? '');
Uses PHP 8 null-safe syntax so 404 pages without an active menu never throw errors.
templates/seu_template/index.php
<?php
$menuitemalias = JFactory::getApplication()->getMenu()->getActive()->alias;
Direct Joomla 3 snippet via JFactory.

Technical explanation and best practices

Great for adding a deterministic body class (such as page-contact or page-joomla-snippets) automatically without manually typing a page class suffix on every menu item.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.