How to add a class to a specific link in a link list?

Shopify Expert
21 0 3

I need to add a class to a specific link in a link list. The link i need to target will always be the word 'shop'. I tried applying the following to the a link within my link list but it doesn't seem to be working..

<a href="{{ link.url }}" class="{% if link.title contains 'shop' %}site-nav-shop {% endif %}site-nav__link">{{ link.title }}</a>

Any ideas how I can get this to work!?

Thanks in advance

0 Likes
Astronaut
1890 1 395

The search term is case-sensitive.  Try 'Shop' with a capital S.

1 Like
Shopify Expert
21 0 3

Ahh, silly me! Thanks Alex.

0 Likes
New Member
2 0 0

Hi, can you advise where did you add this code? To theme.liquid? Is the class then site-nav-shop? Sorry, I am new to this and trying to figure out how to style my menu SALE button only. Can't seem to find a way how to add class to it. I see this is an old post but hope you can help.

0 Likes