• Resolved benedict1986

    (@benedict1986)


    Hi I have an issue with the background color of menu items with anchor. I have three menu buttons, include a Home button, Articles button and About button.

    Home button links to FrontPage, Articles button links to Posts Page and About button is a Custom Link pointing to an anchor in home page (with url #about). When I am in the home page, I can see that the background color of both Home button and About button are highlighted while that for Articles button is not set. I expect that in Home page, only Home button is highlighted but not for Articles and About button.

    How should I set Mega Menu to achieve this? Thank you

    I haven’t put the website online so the link provided is only a screenshot of the menu, as well as the settings of each item.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi benedict,

    With the About button set to #about, it is actually linking to the homepage (just a certain position on there), so WordPress is picking it up as being a ‘current’ menu item. With ‘Highlight current item’ enabled in the menu theme, it will be highlighted along with the home item.

    There is some code you can use to work around it. First, add this to your themes functions.php file:

    function megamenu_never_highlight( $classes = array(), $menu_item = false ) {
    
        if ( in_array( 'mega-never-highlight', $classes ) ) {
    
        	if ( in_array( 'mega-current-menu-ancestor', $classes ) ) {
        		$classes = array_diff( $classes, array( 'mega-current-menu-ancestor' ) );
        	}
    
        	if ( in_array( 'mega-current-menu-item', $classes ) ) {
        		$classes = array_diff( $classes, array( 'mega-current-menu-item' ) );
        	}
    
        }
    
        return $classes;
    
    }
    
    add_filter( 'megamenu_nav_menu_css_class', 'megamenu_never_highlight', 10, 2 );

    Then add a custom class to the About menu item, the class should be ‘never-highlight’.

    Regards,
    Tom

    Thread Starter benedict1986

    (@benedict1986)

    Awesome. thanks a lot, Tom, this solution works for me.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Menu with anchor has background’ is closed to new replies.