WHMCS is a popular billing and support solution, and you can alter its menus by using hooks. Below is an example of a WHMCS hook that you can use to modify the menu. I’ll include comments to explain what each section does.
<?php
// Hook to alter the menu in WHMCS
add_hook('ClientAreaPrimaryNavbar', 1, function ($primaryNavbar) {
// Check if the menu item you want to alter exists if (!is_null($primaryNavbar->getChild('Home'))) {
// Example: Rename 'Home' menu item to 'Dashboard' $primaryNavbar->getChild('Home')->setLabel('Dashboard');
// Example: Remove he 'Announcements' sub-menu under 'Home'
//$primaryNavbar->getChild('Home')->removeChild('Announcements');
// Example: Add a new sub-menu under 'Home'
//$primaryNavbar->getChild('Home')->addChild('New Item', array(
// 'label' => 'New Submenu',
// 'uri' => 'new_page.php',
// 'order' => '10',
//)); }
// Example: Add a new top-level menu item
//$primaryNavbar->addChild('New Menu', array(
// 'label' => 'New Top Menu',
// 'uri' => 'new_top_page.php',
// 'order' => '100',
//));
// Example: Remove an existing top-level menu item
//$primaryNavbar->removeChild('Existing Menu'); }); ?>
Here’s an explanation of the commented-out examples:
- Rename ‘Home’ Menu Item: This example changes the label of the ‘Home’ menu item to ‘Dashboard’.
- Remove ‘Announcements’ Sub-menu: This example shows how to remove a specific sub-menu item under ‘Home’.
- Add a New Sub-menu under ‘Home’: This example demonstrates how to add a new sub-menu item under ‘Home’.
- Add a New Top-level Menu Item: This example shows how to add a new top-level menu item.
- Remove an Existing Top-level Menu Item: This example demonstrates how to remove an existing top-level menu item.
You can uncomment the examples you wish to use and customise them according to your needs. Make sure to upload this hook file to the appropriate directory in your WHMCS installation, typically under the /includes/hooks/
directory.
Here’s a cheat sheet with various examples for manipulating menus in WHMCS using hooks:
1. Rename a Menu Item
$primaryNavbar->getChild('Home')->setLabel('Dashboard');
2. Remove a Sub-menu Item
$primaryNavbar->getChild('Home')->removeChild('Announcements');
3. Add a New Sub-menu Item
$primaryNavbar->getChild('Home')->addChild('New Item', [ 'label' => 'New Submenu', 'uri' => 'new_page.php', 'order' => '10', ]);
4. Add a New Top-level Menu Item
$primaryNavbar->addChild('New Menu', [ 'label' => 'New Top Menu', 'uri' => 'new_top_page.php', 'order' => '100', ]);
5. Remove an Existing Top-level Menu Item
$primaryNavbar->removeChild('Existing Menu');
6. Set a New URL for a Menu Item
$primaryNavbar->getChild('Home')->setUri('new_home.php');
7. Set a Custom CSS Class for a Menu Item
$primaryNavbar->getChild('Home')->setClass('custom-class');
8. Set an Icon for a Menu Item
$primaryNavbar->getChild('Home')->setIcon('fa-home');
9. Add a Sub-menu Item with an Icon
$primaryNavbar->getChild('Home')->addChild('New Item with Icon', [ 'label' => 'Icon Submenu', 'uri' => 'icon_page.php', 'icon' => 'fa-icon', ]);
10. Swap the Position of Two Menu Items
$primaryNavbar->getChild('First Item')->setOrder(20); $primaryNavbar->getChild('Second Item')->setOrder(10);
These examples provide a concise overview of different ways you can manipulate the menus in WHMCS. Use these snippets as building blocks to customise the menus to fit your needs. Make sure to replace the placeholder names, like 'Home'
, 'New Item'
, etc., with the actual names or keys of the menu items you want to modify.