-
AuthorPosts
-
May 19, 2020 at 8:15 am #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.
May 23, 2020 at 2:46 pm #1215479Hey 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,
VictoriaMay 25, 2020 at 3:30 pm #1216162This reply has been marked as private.May 28, 2020 at 3:20 pm #1217384Victoria,
Did you have any luck with this topic?
Thanks again!!
May 30, 2020 at 4:50 pm #1218033Hi ProTravelGolf,
I see no errors in JavaScript and no causes for the issue. I will ask my colleagues to have a look.
Best regards,
VictoriaMay 30, 2020 at 6:47 pm #1218063Hi,
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,
MikeMay 31, 2020 at 12:37 pm #1218172This reply has been marked as private.May 31, 2020 at 1:49 pm #1218182Hi,
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,
MikeMay 31, 2020 at 4:01 pm #1218192This reply has been marked as private.May 31, 2020 at 5:13 pm #1218194June 1, 2020 at 10:09 am #1218382This reply has been marked as private.June 1, 2020 at 1:21 pm #1218419Hi,
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,
MikeJune 1, 2020 at 3:18 pm #1218445Mike,
That´s brilliant and is now working exactly as I would like it to. Fantastic service as always!
Thanks you so much!!
Best regards
June 2, 2020 at 11:13 am #1218732Hi,
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 -
AuthorPosts
- The topic ‘Highlight active menu’ is closed to new replies.