Get WordPress menu with wp_get_nav_menu_items
The function wp_get_nav_menu_items is easier than wp_nav_menu to custom the mockup of navigation. To detect the current menu, it can use the condition “$nav->object_id == get_queried_object_id()” to add the class you need.
PHP
<ul class="uk-flex uk-flex-middle uk-margin-left navbar" style="width: calc(100% - 160px);height:100%; overflow:scroll"> <?php $navs = wp_get_nav_menu_items('main'); foreach($navs as $nav): ?> <li <?php echo ( $nav->object_id == get_queried_object_id() ) ? 'class="uk-active"':''; ?>> <a class="text-white text-medium uk-text-bold uk-text-nowrap link-secondary" href="<?php echo esc_attr($nav->url); ?>" style="margin-right:25px; letter-spacing:2px"><?php echo esc_html($nav->title); ?></a></li> <?php endforeach; ?> </ul>
Tags:
- menu
- /