Check out the section titled Adding Conditional Classes to Menu Items on the wp_nav_menu
Codex page. This should give you a pretty good overview for adding classes to menu items using the nav_menu_css_class
filter.
For what you asked to do, which is add menu_element
to the class attribute for both the menu item with ID 30, and the menu items listed after it, you could do something like this in your theme’s functions.php
file:
function menu_element_class($classes, $item){
if($item->ID == 30 || $item->menu_item_parent == 30) {
$classes[] = "menu_element";
}
return $classes;
}
add_filter('nav_menu_css_class' , 'menu_element_class' , 10 , 2);
This just checks to see if the menu item has an ID of 30, or has a menu_item_parent of 30, and adds “menu_element” to the classes array. Of course, you can change the if
statement to check for whatever conditions you’d like before adding the class.