Nice approach, however using the itmes title in the id construction, will change the id if the current administrator intercepts with the menu title in menu settings.

Why not using the page id instead?

To add the menu slug will also create an unique id for the same page. Add a third arguments that actually contains the menu information.

add_filter(‘nav_menu_item_id’, ‘nav_id_filter’, 10, 3 );

= function nav_id_filter($id, $item, $args)

and

return ‘nav-‘.$args->menu->slug.’-‘.$item->object_id;

This is what we use:

function nav_class_filter( $var ) {
if(!is_array($var)) return $var;
$pattern = array(
‘current_page_item’,
‘current_page_parent’,
‘current_page_ancestor’,
‘current-cat’,
‘current-menu-item’,
‘current-menu-parent’,
‘current-menu-ancestor’
);
if(!empty(array_intersect($var, $pattern))) return array(‘selected’, ‘selected-onload’);
else return ”;
}
add_filter(‘nav_menu_css_class’, ‘nav_class_filter’, 100, 1);

function nav_id_filter($id, $item, $args) {
return ‘nav-‘.$args->menu->slug.’-‘.$item->object_id;
}
add_filter(‘nav_menu_item_id’, ‘nav_id_filter’, 10, 3 );

Hope this comment doesnt end up to cluttered, I cant find any allowed tags information.

/ Jonas Lundman, Intervik development