renderMenu($menuLocation)
Render a menu from a previously defined location
Usage
site()->renderMenu($menuLocation);
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
$menuLocation | string | Yes | The location of the menu to render, as defined in the config under menu-locations (the key) |
Returns
Type | Description |
---|---|
string | Rendered menu, as HTML string |
The WordPress docs has more information about the structure of the returned HTML.
Example
First we make sure the menu location is registered in the theme’s config.php:
config.php
return [ "menu-locations" => [ "main-nav" => "Main Navigation" ... // More menu locations ]]
Then we echo the rendered menu in the theme’s header view:
<?= site()->renderMenu("main-nav"); ?>
And that’s it!