Jump to content

Code to show main nav as active when on pages that are links to shop category pages?

Go to solution Solved by tuanphan,

Recommended Posts

Hello all,

In the main nav on the website I'm working on, two of the pages in the main nav are just links to specific category pages in the shop.  I removed the "all' from the shop. The client wants to land on "best sellers" when people click the shop button in the top nav. The issue is that the "shop" nav doesn't show as active when in the store using this method. Is there some code I could use that I could insert into each category page for the shop, that would show the top/main nav as active when visiting that page? Hopefully this makes sense. 

Link to comment
  • Solution
18 hours ago, dross said:

Exactly. That's precisely what I'm trying to do. 

Add this code to Website Tools (under Not Linked) > Code Injection > Footer

<script>
  if (document.location.pathname.indexOf("/original-artwork/") == 0) {
    document.querySelector('body').classList.add('shop-artwork')
}
</script>
<style>
  body.shop-artwork header#header div.header-nav-item:first-child [href*="original-artwork"] {
    color: #f56400 !important;
    text-decoration: line-through !important;
}
</style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

I forgot, the code doesn't work on mobile, you can use this new code

<script>
  if (document.location.pathname.indexOf("/original-artwork/") == 0) {
    document.querySelector('body').classList.add('shop-artwork')
}
</script>
<style>
  body.shop-artwork header#header div.header-nav-item:first-child [href*="original-artwork"] {
    color: #f56400 !important;
    text-decoration: line-through !important;
}
   body.shop-artwork header#header div.container.header-menu-nav-item:first-child [href*="original-artwork"] {
    color: #f56400 !important;
    text-decoration: line-through !important;
}
</style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.