Adding an "active" CSS class to the <li> element in menus

I seem to keep finding different ways to add an "active" CSS class to <li> elements in menus. I must have been a bit dense, but it took me a little while to figure that menus are displayed using different methods, hence they need different ways to add in the extra class. Here are the methods:

  1. Using theme_menu_tree e.g. Navigation menu, any menu shown via a block.
    Interesting tidbit here: these menus can have parts of them expanded using the option on the edit menu item page.
  2. Using theme_links e.g. primary and secondary menus when shown via theme('links', $primary_links...) in page.tpl.php.
    These menus will never be expanded using that menu option
  3. OK, got that?? Hehe, don't worry, I'll show you how to fix both methods.

Posted in:

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <b> <i> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <blockquote> <img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is to block spam bots and check if you're human
1
4
X
x
S
E
Enter the code without spaces and pay attention to upper/lower case.
magnanimous-junior