Custom Walker for the wordpress menu structure.
- Download the
navbar.phpfile and copy and paste it into the theme.
git clone https://github.com/Rayiumir/navbar-walker-wordpress.git
cd navbar-walker-wordpress/- Calling the file in
functions.php.
require_once('navbar.php');- Register a new menu by adding the follow code into the
functions.phpfile of your theme.
register_nav_menu('menu-one', 'Menu Header');- Sample HTML menu code:
<ul class="nav-menu">
<li class="nav-item">
<a href="#" class="nav-link">Home</a>
</li>
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-link">Links</a>
<div class="dropdown-menu">
...
</div>
</li>
</ul>- Add the following html code in your
header.phpfile or wherever you want to place your menu.
<ul class="nav-menu">
<?php
wp_nav_menu(array(
'theme_location' => 'menu-one',
'container' => false, // Do not wrap in a div
'items_wrap' => '%3$s', // Only output the list items, not the <ul> wrapper
'menu_class' => '', // Do not add a class to the ul itself, as we already have one
'walker' => new Navbar_Walker(), // Use our custom walker
'depth' => 2, // Allow for dropdowns (adjust as needed for deeper levels)
));
?>
</ul>