Add a Menu Item
You can customize the Client Area’s navigation menus through hooks and custom modules.
For more information about customizing the Client Area’s navigation menus, see Client Area Navigation Menus and our Developer Documentation.
Add a Menu Item
You can add a new link to the primary navigation using the following example code:
<?php
# Adding Menu Item to primaryNavbar
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
$primaryNavbar->addChild('Menu Name')
->setUri('https://www.example.com/')
->setOrder(70);
});
Add a Child Menu Item
You can add additional child menu items using the following example code:
<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
if (!is_null($primaryNavbar->getChild('Support'))) {
$primaryNavbar->getChild('Support')
->addChild('Emergency Contacts', array(
'label' => 'Emergency Contacts',
'uri' => 'emergency.php',
'order' => '100',
));
}
});
Localize the Menu Item Name
To have your menu item use a language file text string for the display label, you can use the Lang::trans
method using the following example code:
<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
if (!is_null($primaryNavbar->getChild('Support'))) {
$primaryNavbar->getChild('Support')
->addChild('Emergency Contacts', array(
'label' => Lang::trans('emergencyContacts'),
'uri' => 'emergency.php',
'order' => '100',
));
}
});
Add a Menu Item Conditionally
To add a menu item conditionally based on client login status, you can do that using the following example code, which uses the page context to determine the client status:
<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
$client = Menu::context('client');
// Only add the menu item when no client is logged in
if (is_null($client)) {
$primaryNavbar->addChild('Example')
->setUri('https://www.example.com/')
->setOrder(100);
}
});
Last modified: November 12, 2024