Edit html for menu items in default frontend menu

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:

Read More
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.

Related posts

Leave a Reply

1 comment