Menu Active Class
-
Hi Jared,
Just getting started, but so far timber is great, thanks for sharing!
I have a question re wp_nav_menu classes. What is the best practise for highlighting a menu with an ‘active’ class.
Normally I sanitised WordPress’s crazy menu class with the function below.
/* Clean up WP Nav Menu CSS Classes */ add_filter('nav_menu_css_class', 'clear_nav_menu_item_class', 10, 3); function clear_nav_menu_item_class($classes, $item, $args) { if (array_search('current-menu-item',$classes) || array_search('current-page-ancestor',$classes) || array_search('current_page_parent',$classes) ) { $active = array(1 => 'active'); } else { $active = array(); } return $active; }
This no longer works, is the Timber menu filterable?
I notice there is an ‘current’ flag I can use, my markup is as follows. Is there a cleaner way to do this.
{% if item.current == true %} <li class="active"> {% else %} <li> {% endif %}
Thanks,
Ian.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Menu Active Class’ is closed to new replies.