add id to menu items

add_filter(‘nav_menu_link_attributes’, function ($atts, $item, $args) {
// Put a class like “id-start-free” in the menu item’s “CSS Classes” field
if (!empty($item->classes) && is_array($item->classes)) {
foreach ($item->classes as $class) {
if (strpos($class, ‘id-‘) === 0) {
$atts[‘id’] = substr($class, 3); // “id-start-free” => id=”start-free”
break;
}
}
}
return $atts;
}, 10, 3);

Scroll to Top
Solution lamp for mobile header

Custom Solutions with Zeevou

Discover tailored solutions perfectly suited to your role, business size, and specific use cases.