WordPress.org

Ready to get started?Download WordPress

Forums

filter wp_nav_menu to add current-menu-item for single.php (3 posts)

  1. Paul Wright
    Member
    Posted 3 years ago #

    Hello,

    With WordPress 3 menus, I'm using wp_nav_menu instead of wp_list_pages. Most of the 'highlight menu item for single pages' tricks are built around the old wp_list_pages call.

    I want to make a filter to add 'current-menu-item' to the correct menu item on single pages. I looked in wp-includes/nav-menu-template.php: Do I attach to one of these areas:

    $items = apply_filters( 'wp_nav_menu_items', $items, $args );
    $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );

    or is there a better way? Can you point me in the right direction?

    Thanks,

    Paul

  2. iaaxpage
    Member
    Posted 3 years ago #

    I am running through the same situation as we speak. I found this article and is very helpful, this shall definitely become part of the wordpress documentation.

    http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output

    Once you have extended the function, you might as well look for the id(or the slug) of the page and add the respective class.

    Hope this helps you as it did help me.

    Regards,

    Iaax Page
    User Experience Design, Web Development and On-Line Marketing Consultant.

  3. Paul Wright
    Member
    Posted 3 years ago #

    Thank you for the reply.

    That looks similar, yes, I'll have a good look through it soon.

Topic Closed

This topic has been closed to new replies.

About this Topic