Home CSS Append a class to the Shopify menu item
CSSShopify for Developers

Append a class to the Shopify menu item

Sometimes you need one menu item to be different than the rest for one reason or another, or you want to add Javascript to a specific item. At times you can solve the visual part with CSS :nth-child() property and target the item you need. In the example below we are targeting the 5th element in our menu/navigation and adding some styling:

.SidebarMenu__Nav:nth-child(5) { background-color: var(--brand-color); color: var(--color-light); }

Eventually, however, you will need to put a class on a Shopify navigation item to achieve what you need. And we will, of course, use the power of Shopify Liquid to achieve this.

Here is a neat little trick I picked up from my buddy Marin.

Shopify liquid “if link.title contains”

<span class="{% if link.title contains "Shop" %} shop-btn {% endif %}">{{- link.title | escape -}}</span>

So basically what we are saying is: if there is a link that contains the word “Shop”, append a class called .shop-btn to it. If not, do nothing.

{% if link.title contains "Shop" %} shop-btn {% endif %}
Written by
Igor Bujas

I am a UI designer and front-end developer professional working mostly in the Shopify ecosystem. I've been working in the industry for so long that I was fixing bugs for IE5, and animating in Flash while it was still a Macromedia product. While not differentiating between the UI and the code, I am always looking to get outdoors for some alpine climbs or scuba dives. I also work as a Krav Maga instructor in Zagreb, Croatia.

Leave a comment

Related Articles

Shopify for Developers

Can you customize your Shopify store without knowing how to code?

Yes, you can customize your Shopify store without knowing how to code...

Shopify flow explained
Shopify for DevelopersShopify for Entrepreneurs

What is Shopify Flow, and how does the Shopify Flow app work?

Shopify Flow is an e-commerce automation platform that allows merchants to create...

Shopify for Developers

Which Shopify plan should I choose?

Choosing the right Shopify plan for your business is an important decision...

Shopify for Developers

Shopify or Wix?

Choosing between Shopify and Wix depends on your specific needs and preferences....

4 proven ways to speed up your Shopify store.

    We respect your privacy. Unsubscribe at anytime.