Created
March 14, 2018 21:56
-
-
Save nickdavis/9947bc968903549afc3950d80db796b7 to your computer and use it in GitHub Desktop.
Get WordPress menu items data and render in a custom loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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