I have a menu listing all of my products categories in Woocommerce. I need to add an attribute data-relation
to each <li>
tag and the value for each one would be the ID of the category.
I success to do it for the <a>
tag. Does it exist a filter for <li>
?
Here is the PHP filter function:
function category_menu_id_attribute ($atts, $item, $args) {
$atts['data-relation'] = $item->object_id;
return $atts;
}
add_filter('nav_menu_link_attributes', 'category_menu_id_attribute', 10, 3);
Thank you for the help.