renderMenu($menuLocation)

Render a menu from a previously defined location

Usage

site()->renderMenu($menuLocation);

Parameters

ParameterTypeRequiredDescription
$menuLocationstringYesThe location of the menu to render, as defined in the config under menu-locations (the key)

Returns

TypeDescription
stringRendered 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:

<?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!