Get menu item objects for theme location

wp_get_nav_menu_items( $menu ) retrieves all the menu item objects for a menu, but you have to specify the menu ID or menu name.

Here’s how to retrieve the menu items for the menu that is in a specific theme location (ex: primary).

$location = 'primary';

$theme_locations = get_nav_menu_locations();
if( empty( $theme_locations[ $location ] ) )
	return;

$menu_items = wp_get_nav_menu_items( $theme_locations[ $location ] );
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk