Support » Fixing WordPress » wp_nav_menu: not returning current-menu-item on my archive menu link

  • Been playing around with the new menu feature and pretty much got everything to work, except one little thing.

    I couldn’t figure out how to add a archive link to my main menu, so I added a custom link to /2010 and labeled it archive. Seemed to work fine, but when I tried to style the css i noticed I didn’t retrieve a current-menu-item on my archive link.

    Anyone got a clue what I should do? Did I add the archive link the wrong way? Is there a more “accepted” way to do it, please tell me.

    My permalink structure is /%category%/%postname%/ if it matters

Viewing 4 replies - 1 through 4 (of 4 total)
  • do you now php? because if you do you can add the folowing filter to your functions.php file inside your theme’s folder

    add_filter	( 'wp_nav_menu_items', 'add_more_links_to nav' );
    function add_more_links_to nav ( $items  ){
    	$items .= '<li class="menu-class"><a href="link-here">archives</a></li>' ;
    	return $items;

    I got some basic understanding of php, some stuff I can figure out, more advanced stuff I need explained.

    Your code did work, but not in a optimal way, since I got 4 menus on my site and it added archive to all of them. Even if there was a solution to assign it to the right menu, i still don’t think this is the solution I was looking for.

    Maybe I wasn’t clear enough in my first post but I want to use the new menu feature in 3.0 and let my client have the option to rename it, change the order of the menu and yes all those features that comes along with the new menu system.

    I just have trouble finding the right way to add a working archive link to the menu. My current is taking me there but not getting the current-menu-item when selected.

    Don’t know if this is the same thing but my sidebar Archive Widget doesn’t return any classes. all I get is:

    <li><a href='' title='may 2010'>may 2010</a></li>
    <li><a href='' title='april 2010'>april 2010</a></li>
    <li><a href='' title='mars 2010'>mars 2010</a></li>

    while my sidebar Category Widget gives me:

    <li class="cat-item cat-item-7 current-cat"><a href="" title="news">News</a></li>
    <li class="cat-item cat-item-6"><a href="" title="project">Project</a></li>
    <li class="cat-item cat-item-4"><a href="" title="stuff">Stuff</a></li>

    I’m using the standard widget, is something wrong or don’t WordPress just support this?

    This is a band-aid at best, but you can use the auto-generated body classes to help fake the current/active status for custom links. It requires adding a class to the custom link (in screen options) and then pulling a unique (auto-generated) body class from the corresponding page.

    In my case I added a “currentpageitem” class to the custom link, and pulled a “type-location” class from the body on the corresponding page. The CSS looks like this:

    #access li.current_page_item a,
    body.type-location #access li.currentpageitem a {
    color: #a00e2b;

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_nav_menu: not returning current-menu-item on my archive menu link’ is closed to new replies.