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.

I am running Multisite, and would like to be able to append menu items to all frontend menus on all sites. This should work for menus saved via the admin interface as well as the default menu that is displayed.

This code works for saved menu items, but not the default menu:

add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );

function your_custom_menu_item ( $items, $args ) {
    $items .= '<li>my menu item</li>';
    return $items;
}

So my question is, how can I achieve functionality similar to that in the code above for the default front end menu? Ideally, I would be able to prepend/append the generated html for the menu items regardless of how they were generated (saved menu / default menu).

Alternatively, any information about how WP generates the default menu would be helpful.

I can say that the wp_nav_menu_times filter is not even triggered with the default menu. The function wp_nav_menu in wp_includes/nav_menu_template.php that applys the filter returns early (before most work including the application of filters) if no menu is found by wp_get_nav_menu_object.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

add_filter( 'wp_page_menu', 'your_custom_menu_item', 10, 2 );

share|improve this answer
    
This solution is workable but there are two problems. 1 - this allows me to prepend/append the generated html for the entire menu, but not the menu items. I could do some fancy string modification, but this is less than ideal. 2 - This solution doesn't work for saved menus. Ideally, the solution would work regardless of how the menu is generated. –  SomewhereThere Mar 27 '12 at 17:55
    
I've accepted this, and implemented it. As mentioned I did have to slice up the generated html for the menu so I could append some items, but after searching around the codex and core, I don't see another option. –  SomewhereThere Mar 29 '12 at 18:59
add comment

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.