I've been reading a lot about this but couldn't find a solution.
Basically I'm trying to show a current menu item on a dynamic page that is created by a custom page type archive. The default menu control doesn't add the current-menu-item CSS class names. I've found a solution here - http://bloggingsquared.com/blogging-tips/how-to-add-the-current-menu-item-css-class-to-a-custom-link-in-a-wordpress-menu/
Which is like this:
add_filter('nav_menu_css_class', 'AddCurrentMenuItemClass',1,2); function AddCurrentMenuItemClass($classes,$item) { $link = site_url().$_SERVER['REQUEST_URI']; if(strpos($link, $item->url) !== false) { $classes[] = 'current-menu-item'; } return $classes; }
The problem I'm having is that the Home page (which is a custom menu item) is highlighted as well as the page I'm on. If I change the if statement to:
if ( $link == $item->url )
Then in works on that page as but not on sub pages.
Can you please help me sort this out? I'm working on a client project with a right deadline...
I'm on WP 3.4.2 with a premium WooThemes template: Whitelight
current-menu-item
class as well as the page you are viewing? Is that right?