Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created March 14, 2018 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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