function NMIC_limit_classes($oldclasses, $item) { // $oldclasses = array of classes WP wants to append; $item = WP $item object // If there are any custom classes, push them into a new array $custom = get_post_meta($item->ID, '_menu_item_classes', true); // Avoid pushing any empty values into $newclasses array if ($custom && $custom[0] && $custom[0] !== '') { $newclasses = $custom; } // Get a slugified-version of the target page/post title $current = NMIC_slugify_string($item->post_type === 'page' ? $item->post_title : $item->title); // Push that title into the $newclasses array $newclasses[] = $current; // Grab the options object $options = get_option('plugin_options'); // Loop through all the WP classes and push any that match the owner's list into the $newclasses array foreach ($oldclasses as $class) { $option = 'nmic_' . $class; if (isset($options[$option]) && $options[$option]) { $newclasses[] = $class; } } // Return the new list of classes to WP return $newclasses; }
function NMIC_add_id_attribute( $id, $item ) { // Add an ID to the nav item return 'nav-'.NMIC_slugify_string($item->title); }