user2498890
user2498890

Reputation: 1566

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

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.

Upvotes: 0

Views: 1338

Answers (1)

Steph Sharp
Steph Sharp

Reputation: 11682

I tested your code and got it working in my test site. A couple of things to check:

  1. It's case sensitive, so check that your link titles contain 'shop' and not 'Shop' or something else.
  2. Make sure you've got your code in the right place. E.g. I noticed in the Timber theme there is a regular site nav and a mobile site nav. Check you're not adding the class to the wrong <a>...</a>.

Upvotes: 1

Related Questions