To add a âSee Moreâ functionality (often referred to as a collapsible description) on a product page in Shopify, youâll need to customize your themeâs product description code. Shopify doesnât offer this functionality natively, so youâll need to manually add it by editing the themeâs files. Hereâs how you can do it:
Step 1: Backup Your Theme
Before making any changes, itâs always a good idea to duplicate your theme. This ensures you can revert to the original if something goes wrong.
- Go to Online Store > Themes.
- Find your active theme and click Actions > Duplicate.
Step 2: Edit the Product Template
Youâll be modifying the product template to add a collapsible section for the product description.
- Go to Online Store > Themes.
- Find your active theme, and click Actions > Edit Code.
- In the Templates folder, look for the file named product.liquid (or similar, such as
product-template.liquid
if youâre using a different naming convention).
- Open this file and locate the code that outputs the product description. It may look something like this:
{{ product.description }}
Step 3: Add the Collapsible HTML and JavaScript
Youâll need to add some HTML and JavaScript to make the description collapsible.
- Add the HTML structure around the description code:
<div class="product-description-container">
<div class="product-description" id="product-description">
{{ product.description | escape }}
</div>
<button id="see-more-btn" class="see-more-btn">See More</button>
</div>
- Add the JavaScript to control the collapsing and expanding:
Inside the same file or in the themeâs assets folder (in a new file or an existing JavaScript file), you can add the following Javascript:
<script>
document.addEventListener("DOMContentLoaded", function() {
const description = document.getElementById('product-description');
const seeMoreBtn = document.getElementById('see-more-btn');
const maxHeight = 200; // Adjust this value based on how much description you want visible initially.
// Initially truncate the description
if (description.scrollHeight > maxHeight) {
description.style.maxHeight = maxHeight + 'px';
description.style.overflow = 'hidden';
seeMoreBtn.style.display = 'inline-block'; // Show the "See More" button
}
// Toggle description visibility when the button is clicked
seeMoreBtn.addEventListener('click', function() {
if (description.style.maxHeight === maxHeight + 'px') {
description.style.maxHeight = 'none';
seeMoreBtn.textContent = 'See Less';
} else {
description.style.maxHeight = maxHeight + 'px';
seeMoreBtn.textContent = 'See More';
}
});
});
</script>
Step 4: Style the Button (Optional)
To style the âSee Moreâ button, you can add some CSS in your themeâs assets > theme.scss.liquid (or any other CSS file):
.product-description-container {
position: relative;
max-width: 100%;
}
#see-more-btn {
display: none;
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
margin-top: 10px;
font-size: 14px;
}
#see-more-btn:hover {
background-color: #0056b3;
}
.product-description {
transition: max-height 0.3s ease;
}
Step 5: Test the Changes
Once youâve made these changes, preview your product page and ensure that:
- The description is truncated initially (if itâs long).
- The âSee Moreâ button works to expand and collapse the description.
- The button text changes between âSee Moreâ and âSee Less.â
Step 6: Save and Publish
After testing everything, save the changes and publish the updated theme.
This method adds a âSee Moreâ button that dynamically shows or hides parts of the product description. If youâd like more advanced styling or functionality