Ecommerce Shopify WordPress Discussion

Shopify – Logic to display handle of pages, collections, products and index on <body id="handle">?

Problem I've found partial answers to this (like here and here) but get mixed results because it seems like grabbing the page handle is different depending on if the current page is a collection, a product, a page, a blog or index - is that correct? Sorry if this is easy, I'm just a designer so am probably using incorrect search terms. Attempt I've been adding logic to the body tag with mixed results like this... <body {% if != "index" %}id="{{ page.handle }}"{% endif %} class="{{ template }}{% if template == "product" %} {{ product.handle }}{% endif %} {% if template == "collection" %} {{ collection.handle }}{% endif %}" > Question If possible, I'd prefer to define a variable like "bodyID" or "bodyClass" and use logic to grab the handle no matter the page-type - is this possible? Something like... {% bodyID = ...logic to grab handle no matter the page-type... %} <body id="{{ bodyID }}" Or is there another way people do this? Any help much appreciated. Cheers
OK, after more searching I found this and with a bit of logic to handle the index use case, this works and adds useful ID and class hooks onto the body tag... <body {% if == "index" %}id="index"{% else %}id="{{ handle }}"{% endif %}> If anyone has a better way, let me know.

January 20, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.