Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created March 14, 2018 21:56
Show Gist options
  • Save nickdavis/9947bc968903549afc3950d80db796b7 to your computer and use it in GitHub Desktop.
Save nickdavis/9947bc968903549afc3950d80db796b7 to your computer and use it in GitHub Desktop.
Get WordPress menu items data and render in a custom loop
<?php if ( has_nav_menu( 'how-can-we-help-you' ) ) :
$menu_slug = get_term( get_nav_menu_locations()['how-can-we-help-you'], 'nav_menu' )->slug;
$menu_items = wp_get_nav_menu_items( $menu_slug );
?>
<ul>
<?php foreach ( $menu_items as $menu_item ) : ?>
<li><a href="<?= $menu_item->url; ?>"><?= $menu_item->title; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment