Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1214219

    Hello,

    I have a couple of pages on the website which can be accessed directly from 2 different drop down menus. However, when the page is accessed by one of these menu links both main menu items then get highlighted as the active page lies within both of them. Is there a way to prevent this so that the active menu is only highlighted for where the page link was clicked from?

    Please see the link to one of the pages in question below and you will see how 2 menu items are highlighted white.

    Many thanks in advance for your help.

    #1215479

    Hey ProTravelGolf,

    Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?

    Best regards,
    Victoria

    #1216162
    This reply has been marked as private.
    #1217384

    Victoria,

    Did you have any luck with this topic?

    Thanks again!!

    #1218033

    Hi ProTravelGolf,

    I see no errors in JavaScript and no causes for the issue. I will ask my colleagues to have a look.

    Best regards,
    Victoria

    #1218063

    Hi,
    Thank you for the link, I see that your two menu items are both getting marked as the “current page”, probably due to your menu structure. For this page which menu item do you want to be highlighted?
    From your description above it sounds like you only have a couple of pages with this issue, if you link to each page and tell us which menu items should be highlighted we can provide some css to correct this.

    Best regards,
    Mike

    #1218172
    This reply has been marked as private.
    #1218182

    Hi,
    Thanks for your explanation, I wrote this script to check the URL hash and then remove the menu highlighting class from one of the menu items. So for the is work please add hashes to your two menu items, for the sub-menu item “la-manga-club” under “VIP Teaching Weeks” change the hash to #vip , for the sub-menu item “la-manga-club” under “TOS Teaching Weeks” change the hash to #tos .
    There are no anchors for #vip or #tos so the page will load at the top, but this will tell us which menu item the visitor clicked to get to the page.
    Try adding this code to the end of your functions.php file in Appearance > Editor:

    function custom_landing_script(){
      ?>
      <script>
    (function($){
      $(document).ready(function(){
    if (window.location.hash == '#vip'){
    	setTimeout(function(){
    	$("#top.page-id-497 #menu-item-6449").removeClass("current-menu-item");
    	},300);
    } else if (window.location.hash == '#tos'){
    	setTimeout(function(){
    	$("#top.page-id-497 #menu-item-1077").removeClass("current-menu-item");
    	},300);
    } else {}
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_landing_script');

    Then clear your browser cache and check.

    Best regards,
    Mike

    #1218192
    This reply has been marked as private.
    #1218194

    Hi,
    Sorry, above I described adding these as if you were using the “custom” menu items but you are actually using a standard menu item. So please replace the two menu items with custom menu items with the URL /la-manga-club#vip & /la-manga-club#tos
    2020-05-31_111100.png

    Best regards,
    Mike

    #1218382
    This reply has been marked as private.
    #1218419

    Hi,
    Well it seems that when changing the menu items to custom it removes the highlighting, so I adjusted the menu and the script and it seems to be working now.
    Please clear your browser cache and check.

    The new script is:

    function custom_landing_script(){
      ?>
      <script>
    (function($){
      $(document).ready(function(){
    if (window.location.hash == '#tos'){
    	setTimeout(function(){
    	$("#top.page-id-497 #menu-item-1077").removeClass("current-menu-item");
    	$("#top.page-id-497 #menu-item-6449").addClass("current-menu-item");
    	},500);
    } else {}
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_landing_script');

    menu-item-1077 is the standard menu item that gets highlighted, menu-item-6449 is a custom menu item that doesn’t get highlighted but it adds the hash #tos to the URL that fires the script above.

    Best regards,
    Mike

    #1218445

    Mike,

    That´s brilliant and is now working exactly as I would like it to. Fantastic service as always!

    Thanks you so much!!

    Best regards

    #1218732

    Hi,
    Glad we were able to help, we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Highlight active menu’ is closed to new replies.