I have the following function in my project:
function cr_get_menu_items($menu_location) { $locations = get_nav_menu_locations(); $menu = get_term($locations[$menu_location], 'nav_menu'); return wp_get_nav_menu_items($menu->term_id); } The function is used in my theme like this:
<?php $nav = cr_get_menu_items('navigation_menu') ?> <?php foreach ($nav as $link): ?> <a href="<?= $link->url ?>"><?= $link->title ?></a> <?php endforeach; ?> This currently returns all navigation items present in my menu - parent/top-level and sub navigation. I am wondering how to alter this to exclude all sub navigation items. I only want to display the parent/top-level items.
menu_item_parent... the selected answer does provide a solution IF the question was "Return only top-level pages as navigation items"... @Aness answered below and seems to provide the solution best fitting the OP's question (even if it is disappointing to have to post-filter the menu items). MY QUESTION : can/should we reword the OP's question to better match the answer?