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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk