Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to render WordPress menu items without a custom walker
<?php $menu_location = 'some_menu_location'; ?>
<?php if ( has_nav_menu( $menu_location ) ): ?>
<?php $menu_items = wp_get_nav_menu_items( wp_get_nav_menu_name( $menu_location ) ); ?>
<?php foreach ( $menu_items as $menu_item ): ?>
<a href="<?= $menu_item->url ?>"
target="<?= $menu_item->target ?: '_self' ?>"
class="<?= implode( ' ', $menu_item->classes ) ?>"><?= $menu_item->title ?></a>
<?php endforeach; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.