Title: Menu Active Class
Last modified: August 22, 2016

---

# Menu Active Class

 *  [ianatkins](https://wordpress.org/support/users/ianatkins/)
 * (@ianatkins)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/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.
 * [https://wordpress.org/plugins/timber-library/](https://wordpress.org/plugins/timber-library/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [jarednova](https://wordpress.org/support/users/jarednova/)
 * (@jarednova)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/menu-active-class/#post-5382205)
 * Hey Ian! I’m looking into issues with the filterability of menu classes; something
   that should be a part of the next version. For your example, here’s what I recommend:
 *     ```
       <li class="{{ item.current ? 'active' }}">
       ```
   
 *  Thread Starter [ianatkins](https://wordpress.org/support/users/ianatkins/)
 * (@ianatkins)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/menu-active-class/#post-5382302)
 * Hey, thanks for the reply.
 * I look forward to future releases! Be great to get logical class naming built
   in.
 * Thanks
 * Ian.
 *  Plugin Author [jarednova](https://wordpress.org/support/users/jarednova/)
 * (@jarednova)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/menu-active-class/#post-5382318)
 * I [@ianatkins](https://wordpress.org/support/users/ianatkins/), I’ve got that
   code ready on a GitHub PR if you’re interested:
 * [https://github.com/jarednova/timber/pull/376](https://github.com/jarednova/timber/pull/376)
 * … this will be added to the GitHub master branch soon and then pushed to WP.org—
   I’m interested in any tests/feedback you have based on your setup. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Menu Active Class’ is closed to new replies.

 * ![](https://ps.w.org/timber-library/assets/icon-256x256.png?rev=1482054)
 * [Timber](https://wordpress.org/plugins/timber-library/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/timber-library/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/timber-library/)
 * [Active Topics](https://wordpress.org/support/plugin/timber-library/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/timber-library/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/timber-library/reviews/)

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [wp_nav_menu()](https://wordpress.org/support/topic-tag/wp_nav_menu/)

 * 3 replies
 * 2 participants
 * Last reply from: [jarednova](https://wordpress.org/support/users/jarednova/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/menu-active-class/#post-5382318)
 * Status: not resolved