WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to strip out the title / url from a custom navigation as to create a new HTML structure?

I'm creating a very unique menu structure, based on the custom menu created by a user in WordPress, but wp_nav_menu() does not seem to output only the title / url into an array. I could most likely get the HTML output from wp_nav_menu() and run a regex to strip out the various elements I need, but this seems overkill if a method already exits?

Appreciate the help.

share|improve this question

The wp_get_nav_menu_items() function returns an indexed array of WP_Post objects.

Here is an example:

$menu_name = 'custom_menu_slug';
$menu_locations = get_nav_menu_locations()
$menu = wp_get_nav_menu_object( $menu_locations[ $menu_name ] );

$menu_items = wp_get_nav_menu_items( $menu->term_id );

$menu_list = '<ul id="menu-' . $menu_name . '">';

foreach ( (array) $menu_items as $key => $menu_item ) {
    $menu_list .= '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>';

$menu_list .= '</ul>';    

Source: http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items

share|improve this answer
I tried that, but I couldn't get the output like you outline. I'll take another look at the code, thank you. – JadedEric Apr 29 '14 at 19:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.