Rest-Easy icon indicating copy to clipboard operation
Rest-Easy copied to clipboard

Custom classes for WpMenuItems don't show up

Open drewbaker opened this issue 6 years ago • 2 comments

If I try to add the category ID of a menu item as a menu item class, it doesn't end up on the final menu item.

This doesn't work:

     function add_dev_id_to_nav_items($nav_item_data){


         if ( isset($nav_item_data['id']) ) {
             // get full nav item
             $object_type = get_post_meta($nav_item_data['id'], '_menu_item_object', true);
             $object_id = get_post_meta($nav_item_data['id'], '_menu_item_object_id', true);

             if ( $object_type == 'category' ) {
                 $nav_item_data['classes'][] = 'category-id-'.$object_id;
             }

             //var_dump($nav_item_data); die;
         }

         return $nav_item_data;
     }
     add_filter('rez_serialize_nav_item', 'add_dev_id_to_nav_items');

drewbaker avatar Aug 11 '18 00:08 drewbaker

@drewbaker Are you still running into this issue? Just checking before diving in - at first glance, we might have found a Vue-ier way of doing it since then. Thanks!

SaFrMo avatar Oct 30 '18 20:10 SaFrMo

Yeah this was on Story Attic, the last site I built. Would love to improve the menus, always seems finicky and manual to get the right classes on them (specially when it comes to News, categories or blog posts).

drewbaker avatar Oct 30 '18 21:10 drewbaker