WordPress.org

Forums

current menu item and anchor links (1 post)

  1. streettb
    Member
    Posted 1 year ago #

    Here is my problem:

    I currently have a number of anchor (jump) links within the default WordPress menu in the 2012 theme.

    If I click on one anchor link in a list, it highlights all anchor links (because the theme is set to add the current-menu-item class to a menu item if it's on a page).

    However, I just want one highlighted.

    I've been able to remove the current-menu-item class through jquery if I'm already on the page:

    $('#menu-item-19 .sub-menu li').on('click', function(){
    $('.current-menu-item').removeClass('current-menu-item');
    $(this).addClass('current-menu-item');
    });

    But the above only removes the .current-menu-item class if it already exists. How do I have just one anchor link highlight in the WordPress menu if I'm not already on the page?

Topic Closed

This topic has been closed to new replies.

About this Topic