An "accordion" is a great way to display the FAQ to your ecommerce store, since it allows the user to quickly and easily browse your FAQ without much scrolling. And luckily, it's simple and easy to add one to your store!
Demo
This is the first question
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin tincidunt cursus eros et porta. Sed a elit tellus. Vivamus imperdiet nunc non orci faucibus, a ornare metus ultrices. Nulla vitae sapien in sapien elementum convallis.
This is the second question
Cras varius faucibus bibendum. Curabitur sit amet arcu aliquam felis ultrices rutrum. Ut auctor neque augue, in egestas elit blandit pellentesque.
This is the third question
Suspendisse ac rutrum nibh. Praesent sit amet tempor neque. Donec sed tortor felis. Nunc eu eros urna. Nunc vulputate porta ligula id mattis. In tempus massa eu risus congue commodo. Phasellus quis sapien ac lorem suscipit feugiat.
I've made this video tutorial walking you through how to add this FAQ accordion to your Shopify store. The steps are also written below.
Step 1: Download the ZIP file of necessary assets.
Click the link above to download now. Unzip it, and then upload the 3 files inside to the "Assets" folder of your Shopify template editor. If you're not sure how to do this, watch the video above and I'll walk you through it.
Step 2: Create a new page template in your Shopify template editor
You can name it whatever you want, but I recommend something simple like "faq."
Step 3: Paste the following code at the very bottom of your new page template:
<script type="text/javascript" src="{{ 'jquery_accordion.js' | asset_url }}"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.accordion').accordion({
defaultOpen: 'section1',
cookieName: 'accordion_nav'
});
});
</script>
<style>
.accordion {
margin: 0;
padding:10px;
border-top:#f0f0f0 1px solid;
background: #cccccc;
text-decoration:none;
color: #000;
font-size:1em;
position:relative;
}
.accordion-open {
background:#50b3da;
color: #fff;
}
.accordion-open span {
display:block;
position:absolute;
right:3px;
top:25%;
padding:10px;
}
.accordion-open span {
background:url('{{ 'minus.png' | asset_url }}') center center no-repeat;
}
.accordion-close span {
display:block;
position:absolute;
right:3px;
top:25%;
background:url('{{ 'plus.png' | asset_url }}') center center no-repeat;
padding:10px;
}
.faqpage div.container {
padding:0;
margin:0;
}
.faqpage div.container {
max-width:100%;
padding:5px 0;
}
.faqpage div.content {
background:#f0f0f0;
margin: 0;
padding:10px;
font-size:.9em;
line-height:1.5em;
}
.faqpage div.content ul {
padding:0;
margin:0;
padding:3px;
}
.faqpage div.content p {
padding:0;
margin:3px 0 10px;
padding:3px;
}
.faqpage div.content ul li {
list-style-position:inside;
line-height:25px;
}
</style>
IMPORTANT: On the new page template you just made, find a <div> tag above the {{ page.content }} tag. Add the class "faqpage" to this div. When finished, it should look something like this (if there are other words between the quotes already, that's fine--don't remove them):
<div class="faqpage">
If this is confusing, watch the video above.
Step 4: Create a new page called "FAQ." Save, then change the page to the new template.
Step 5: Paste the following code into the page:
<div class="accordion" id="section1">Question 1<span></span></div>
<div class="container">
<div class="content">
<p>This is the answer to question 1.</p>
</div>
</div>
<div class="accordion" id="section2">Question 2<span></span></div>
<div class="container">
<div class="content">
<p>This is the answer to question 2.</p>
</div>
</div>
<div class="accordion" id="section3">Question 3<span></span></div>
<div class="container">
<div class="content">
<p>This is the answer to question 3.</p>
</div>
</div>
Step 6: Edit the contents to your heart's content!
Need help?
If you need help installing this feature on your site, I recommend that you post a job on Storetasker. Storetasker is a platform that will connect you with vetted Shopify developers who can give you a reasonable quote for small store updates like this.
Note: The Storetasker link above is an affiliate link, which means that if you hire a developer to help you install this code, I'll receive a commission at no extra cost to you. If you choose to use this affiliate link, I'm grateful for your support!
87 comments
Thanks, I appreciate your support!
Sure, here is one page for example,
http://www.guy-morgan.com/collections/hydrate
I’ve also just run into another problem unfortunately. On this page, http://www.guy-morgan.com/collections/masks – The sections automatically close when clicking on them. I tried hiding each product in turn to suss out the broken one, but oddly both work if the collection page is just showing one product. I don’t have this problem with any of the other collection pages. The html in the product descriptions as far as I can tell are exactly the same as the rest.
Thanks again! – Guy.
When I visit the Hydrate page, the About section is open by default. However, I noticed that if I close it, leave the page, and come back, it’s still closed. So I think it will be open for first-time visitors. I looked at the page’s source code, and it looks like it may be using a cookie to do this. You could try removing the line “cookieName: ‘accordion_nav’” from your code and that may help to make sure it’s always open by default.
Regarding the second problem, this is probably happening because you are showing the accordion multiple times on the same page. Each section in a single accordion has an ID (for example, “section1,” “section2,” etc. IDs need to be unique, or the accordion will not work correctly. Since you have multiple accordions on one page, you’ve got multiple section1s, multiple section2s, etc. I’d probably recommend not showing the accordions on the collection page, or if you have to, give each one a unique ID. For example, the IDs could be [product-handle]-section1, [product-handle]-section2, etc. Does that make sense?
Thanks, your help is really appreciated. I seemed to have got it working. I think it was due to me placing the code in the product-detail.liquid snippet, rather than the main theme.liquid. (I confess I’m guessing and using my initiative most of the time creating my site, and living off tutorials such as yours!)
Your tip on removing the cookie seems to have done the trick, the first section is open by default now on all descriptions.
-Guy.
Hi Leighton – just dropped you an email as I’m having an issue with the plus image ending up in my header. I’ve tried all the solutions mentioned above and I’m still stuck! Many thanks in advance!
Hi,
Please guide me to change the mouse pointer to hand symbol when hovered over the question bar. Thanks in advance
Regards