Full control over WordPress menus.

Sometimes you just need 100% control over your WordPress menus.

Categories: Development, WordPress

Calling wp_nav_menu() directly has its place, but typically your walker function that might generate a Bootstrap compatible main menu might not be ideal for a footer, location selection, or sidebar link list.

Using wp_get_nav_menu_items() will give us access to every part of the menu object. Title, Link, Class name, and window location.

<ul>
<? $location_menu = wp_get_nav_menu_items('Custom Menu'); 
foreach ($location_menu as $location): ?>
    <li><a href="<?= $location->url ?>"><?= $location->title ?></a></li>
<? endforeach; ?>
</ul>

Don’t forget to register your custom menu!

register_nav_menus( array(
    'custom-menu' => 'Custom Menu'
) );

I also wrote about how you can create
Bootstrap centred nav menus as well as Proper WordPress menus with Bootstrap 4.


Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!