Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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 at 19:45

Your Answer

 
discard

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.