Allow filtering of css classes for Nav items

As per this discussion:

Following on from this feature request:

And this previous thread:

I have created this feature request for easier tracking of this specifically.

We really need to be able to set the current class on custom post type parent archives when viewing a post of that type. This will only be possible when Cwicly allows filtering of the classes.

Given the upcoming 1.3 release I appreciate the focus is on that. I am just re-requesting this, as we have a website releasing this week and we can’t highlight certain menu items due to this issue so for us this is high priority.

Please take a look at adding this soon, thanks.

@Louis, thanks again for all of the recent updates.

As this is the only major missing feature with no current workaround, I am just highlighting it again. Using the Nav block we really need more control over the css for each item, so we can fill in what is missing by default in WordPress with regards to highlighting certain hierarchical nav menu items.

We will really appreciate you including this when possible. Thank you!

1 Like

@Louis, The 1.3.2 release was fantastic. Now that you have made it so the WP menu css classes are being dynamically added we will be extremely grateful if you can also enable the filtering of css classes via wp_get_nav_menu_items.


Hello @StrangeTech,

At the risk of repeating myself, we retrieve menu items using wp_get_nav_menu_items. There is no necessity for us to enable filtering for this function as it is managed by WordPress.

Or am I missing something?


Thank you for confirming @Louis. Looking at the Cwicly codebase I can see that it includes the classes as you rightly say, so technically this should work now - running our code it currently doesn’t, so I will investigate and confirm when I have isolated the cause of the issue.

The general structure of our code looks something like this:

function highlight_custom_posts_taxonomy_menu_items( $items ) {
    foreach ( $items as $key => $item ) {
		$item->classes = update_menu_item_classes($item->classes, $item);

    return $items;

add_filter( 'wp_get_nav_menu_items', 'highlight_custom_posts_taxonomy_menu_items' );

The highlight_custom_posts_taxonomy_menu_items effectively returns the updated array of classes for each item. Let me know if we are not doing it correctly.

@Louis, thanks again for all of your efforts.

Upon further testing I can confirm this now works, so it can be marked as done.

@Araminta, just fully confirming that as of the latest Cwicly version this works perfectly now and can be marked as done.

1 Like

Hello @StrangeTech,

Thanks for confirming that this is now working on your end!


Hi Steange Tech…. I’m still looking for a snippet that make a menu item active when a post of a determined category is displayed ( usually a cpt )
And good news in these days ?
Thanks :blush:

Yes indeed, we have this working on multiple sites now - I will share a general solution here as soon as I have time, it has been a very very busy 2023 and 2024 is even more so!