Skip to content

Instantly share code, notes, and snippets.

@stephpolinar
stephpolinar / full-url.liquid
Last active December 2, 2024 04:48
Get full URL of current page (including queries). Then noindex URLs with 'pr_prod_strat'
<!-- To be placed on theme.liquid WITHIN <head> tags -->
<!-- No index product recommendation URLs =========================================================== -->
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring
| split: '"pageurl":"'
| last
| split: '"'
| first
| split: '.myshopify.com'
@stephpolinar
stephpolinar / readmore-truncate-2.liquid
Last active April 2, 2025 23:48
A version of implementing a "Read more" button in collection descriptions using line-clamp.
<!-- HTML -->
<div class="collection-description short">
{{ collection.description }}
</div>
<a id="description-toggle" class="read-more">Read more</a>
<!-- CSS -->
<style>
.collection-description.short {
display: box;
@stephpolinar
stephpolinar / custom-breadcrumbs.liquid
Last active November 21, 2024 06:18
Implementing custom breadcrumbs (PDP & PLP) with BreadcrumbList schema
{% liquid
if request.page_type == 'product'
assign breadcrumbs = product.metafields.custom.parent_breadcrumbs.value
assign title = product.title
elsif request.page_type == 'collection'
assign breadcrumbs = collection.metafields.custom.parent_breadcrumbs.value
assign title = collection.title
endif
%}
@stephpolinar
stephpolinar / collection-copy.liquid
Last active July 22, 2024 00:04
Section displaying the collection copy/description with 'read more' button. A friendlier version of implementing a "Read more" button in collection descriptions for Shopify themes.
{% comment %}
If the user is planning to have long collection descriptions, they would just have to add <!-- Read More-->
at the top of the paragraph(s) that they want to be included in the "more" section of the description.
{% endcomment %}
{% assign truncated_description = collection.description | split: '<!-- Read More -->' | first %}
{% assign rest_of_description = collection.description | split: '<!-- Read More -->' | last %}
<div class="page-width">
@stephpolinar
stephpolinar / image-preloader.liquid
Created July 21, 2024 23:49
Image preloader section for Shopify themes
<!--
Section is added above the header section (in the customiser) AND
{% section 'image-preloader' %} is also added in the theme.liquid file just above the </head> tag.
-->
{% comment %} Product Page {% endcomment %}
{%- if section.settings.main_product -%}
{%- if template.name == 'product' and product -%}
{%- assign image = product.featured_image -%}
<link
@stephpolinar
stephpolinar / readmore-truncate.liquid
Last active July 21, 2024 23:52
A version of implementing a "Read more" button in collection descriptions
<!--
This is assuming that the paragraphs you want to truncate are enclosed in a span tag with ID="more"
(e.g. Less collection description here... <span id="more">More collection description here...</span>)
-->
<!-- CSS -->
<style>
#more {
display: none;
}
@stephpolinar
stephpolinar / metafield-key.liquid
Last active June 17, 2024 04:59
Makes use of user-inputted text to access metafields
<!-- Metafield list -->
{%- liquid
assign image_key = section.settings.image | downcase | replace: " ","_"
assign image = article.metafields.my_fields[image_key].value
assign title_key = section.settings.title | downcase | replace: " ","_"
assign title = article.metafields.my_fields[title_key]
assign text_key = section.settings.text | downcase | replace: " ","_"
assign text = article.metafields.my_fields[text_key]