A user is trying to display products in random order on their Shopify homepage’s product list section. They attempted to modify the product-list.liquid file using Liquid filters like shuffle or sample, but encountered problems including Liquid errors and broken pagination functionality.
The user is seeking guidance on:
The correct Liquid code or method to randomize product display
A solution that preserves existing design and layout
An approach that works safely within section files like product-list.liquid
The discussion remains open with no responses or solutions provided yet.
Summarized with AI on October 31.
AI used: claude-sonnet-4-5-20250929.
I want the products on my Shopify homepage (product list section) to appear in a random order each time the page is loaded.
I tried editing the product-list.liquid file and used the shuffle or sample filters, but I ran into some issues (Liquid errors or pagination not working).
My goal is simple — I just want the products in the homepage section to display randomly without affecting design or layout.
Could someone please guide me on the correct Liquid code or method to make this work safely in a section like product-list.liquid?
Yes, you can absolutely randomize the products on your Shopify homepage — but since Liquid is rendered server-side and cached, using only Liquid filters like shuffle or sample won’t change the order on every page load.
the easiest and safest method using a little JavaScript (it doesn’t affect your layout or pagination):
Go to: Online Store → Themes → Edit code → Sections → product-list.liquid
Wrap your product loop with a class:
<div class="random-products">
{% for product in collection.products %}
{% render 'product-card', product: product %}
{% endfor %}
</div>
Then open: Layout → theme.liquid (or your theme’s base JS file like global.js)
and paste this script just before the </body> tag:
<script>
document.addEventListener("DOMContentLoaded", () => {
const container = document.querySelector(".random-products");
if (!container) return;
const items = Array.from(container.children);
for (let i = items.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
container.appendChild(items[j]);
}
});
</script>
Each time someone loads your homepage, the product cards will appear in a random order — keeping your section design and pagination perfectly intact.
If you ever need help customizing or fixing something in your theme, I’m a Shopify Developer with SEO & CRO expertise — happy to help at affordable rates while ensuring clean and professional results.
Shopify Liquid does not have shuffle or sample filters.
I wonder what quality of advice you get from partners and developers who do not know this.
However, the idea of shuffling product cards with Javascript is proper.
You may want to output, say 50 products and then leave only 4 random ones. This needs to be done early though to avoid layout shift and loading of extra data.
Even the JS code above can be takes as the basis for solution.
Note that some sections (especially slideshow/carousel type ones) may expect as many slides as were output, so selecting some of many may not work there.
Well @John57 is not the topic starter and this is called “thread hijacking”.
Instead of suggesting to open a new topic you continue to post off-topic here.