0

I am using the wordpress menus on a website, but the problem is that one of the links on that menu is www.homepage.com/#order

So, when I am on the homepage, both "home" and "order" links on the menu contain the class current_page_item, which with my css it makes them appear both as the active button.

How can I make it so the #order link never contains that the current_page_item class?

Here's a screenshot of how the menu looks when visiting the homepage and how I set it up on the admin panel:

http://img87.imageshack.us/img87/7666/screenshotrq.png

On the firebug panel you can see that both www.homepage.com and www.homepage.com/#order menu links contain the current_page_item class.

This is the php code I am using to display the menus:

<?php 
$args = array(
    'menu' => 'Top Menu',
     'sort_column' => 'menu_order',
     'container_class' => ' '
);
wp_nav_menu($args); 
?>
4
  • 1
    @Rockxy: Are you using the new "Menus" of WordPress 3.0? (Under Appearance => Menus?) When I look at the code I see the classes current-menu-item and current_page_item, but not current-page, and I can't replicate this situation (only one link "lights up" for me). Can you edit your question to include a screenshot of the admin area and the front side? (Use @Jan if you reply to me in a comment and I get a notification)
    – Jan Fabry
    Feb 17, 2011 at 13:42
  • @Jan Fabry: Yes, I've used the wp3 menus from Appearance => Menus, and you are right current_page doesn't exist, I made a mistake, it's current_page_item the class that cause the link to be "active". I used firebug to see the css and underscores doesn't show up clearly there, so I though it had two classes (current_page and item). I am going to edit the question and show a screenshot of how the menu looks.
    – user3148
    Feb 17, 2011 at 22:05
  • @Jan or @Jan Fabry send the notification? I hope it works :P
    – user3148
    Feb 17, 2011 at 22:38
  • Ah, it only happens when I use the full URL, not when I just use / or /#order for the link. But I see One Trick Pony already solved it, so that's great! The full rules for @username replies are complicated, just remember that the first name you mention with at least three characters will get a notification. So @Roc would also work for you (unless someone else named Roc also participated in the discussion). For me it's easy, both @Jan and @JanFabry would work (you must leave out spaces).
    – Jan Fabry
    Feb 18, 2011 at 6:57

1 Answer 1

1

a bit hacky, but it works:

add_filter('nav_menu_css_class', 'remove_some_menu_classes', 420 ,3);
function remove_some_menu_classes($classes, $item, $args){
  if(strpos($item->url, '#order') !== false)
    // in the 2nd array put the classes you want removed
    return array_diff($classes, array('current_page_item', 'current-menu-item'));

  return $classes;
}
3
  • use # instead of #order to remove these classes from any links containing # anchors... Feb 17, 2011 at 22:49
  • Thanks, that looks good. I shoudl add it on /mytheme/functions.php right?
    – user3148
    Feb 17, 2011 at 23:24
  • yeah. or put that in a .php file inside wp-content/mu-plugins Feb 17, 2011 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.