Code to apply 'current' class to subpages, also applying class to homepage?

I’m using code from an earlier post on here to make sure the ‘current’ class is applied to the master page when sub pages are active.

The code works, however the ‘homepage’ link in the nav bar is also always highlighted.

Here is the code I’m using;

<script>
var Webflow = Webflow || [];
Webflow.push(function() {
var curUrl = location.pathname;
  $('a').each(function() {
    $(this).toggleClass('w--current', curUrl.indexOf($(this).attr('href')) != -1);
  });
});
</script>

Any suggestions on what I need to do?


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

1 Like

Anyone find the solution to this? I’m trying to do the same thing.

Did you guys ever figure out the answer to this? I tried to use this code snippet and ran into the same issue. Anyone have a solution or workaround?

@webflow Where art thou? Please provide feedback on this issue. I have seen many topics about this behaviour, but never an answer. Take responsability here would be my advice.