After publishing the Frames version, I realized not everybody uses Frames, so a Bricks example might be beneficial. This works exactly as the Frames example and can be used on a site that uses both (not ideal).
Adding the accordion
Adding the accordion is straightforward. This step requires nothing else besides noting the ID or assigning an ID.
Adding the button
Insert the button where you want and give it a class of toggle-all. Then, in the attributes, a data attribute with a name of data-n-accordion and a value of the ID of the target accordion needs to be present.

The Code
Here is the JavaScript. I tried adding it to WPCodebox and using the code element, but kept getting an error, so I added it to the Bricks custom code footer section.
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('[data-n-accordion]').forEach(btn => {
const selector = btn.dataset.nAccordion;
const container = document.querySelector(selector);
if (!container) return;
const items = [...container.querySelectorAll('.accordion-title-wrapper')]
.map(title => ({
title,
content: title.nextElementSibling
}))
.filter(p => p.content && p.content.classList.contains('accordion-content-wrapper'));
const isOpen = item => item.title.getAttribute('aria-expanded') === 'true';
const setItemState = (item, expand) => {
item.title.setAttribute('aria-expanded', expand);
item.title.classList.toggle('active', expand);
item.title.parentElement.classList.toggle('brx-open', expand);
item.content.style.display = expand ? 'block' : 'none';
};
items.forEach(item => setItemState(item, isOpen(item)));
const refreshLabel = () => {
btn.textContent = items.every(isOpen) ? 'Hide All' : 'Show All';
};
refreshLabel();
let bulkMode = false; // ← default Bricks behaviour
/* Button click */
btn.addEventListener('click', () => {
const expandAll = items.some(item => !isOpen(item)); // true → open all
items.forEach(item => setItemState(item, expandAll));
/* ───────── THE KEY LINE ───────── */
bulkMode = expandAll; // free-mode only if panels are OPEN
/* ──────────────────────────────── */
refreshLabel();
});
/* Per-panel toggles */
const interceptToggle = ev => {
if (ev.type === 'keydown' && !['Enter', ' '].includes(ev.key)) return;
const header = ev.currentTarget;
const item = items.find(i => i.title === header);
if (!item) return;
if (bulkMode) { // independent toggling
ev.preventDefault();
ev.stopImmediatePropagation();
setItemState(item, !isOpen(item));
refreshLabel();
}
/* else: Bricks native handler runs (one-open style) */
};
items.forEach(item => {
item.title.addEventListener('click', interceptToggle, true);
item.title.addEventListener('keydown', interceptToggle, true);
});
/* update label after native Bricks toggle (only when bulkMode is off) */
container.addEventListener('click', e => {
if (e.target.closest('.accordion-title-wrapper') && !bulkMode) {
requestAnimationFrame(refreshLabel);
}
});
});
});
</script>Demo
Below is a demo using an FAQ custom post type.
Frequently Asked Questions
This is just placeholder text. Don’t be alarmed, this is just here to fill up space since your finalized copy isn’t ready yet. Once we have your content finalized, we’ll replace this placeholder text with your real content.
Question 1
This is just placeholder text. Don’t be alarmed, this is just here to fill up space since your finalized copy isn’t ready yet. Once we have your content finalized, we’ll replace this placeholder text with your real content.
Sometimes it’s nice to put in text just to get an idea of how text will fill in a space on your website.
Traditionally our industry has used Lorem Ipsum, which is placeholder text written in Latin. Unfortunately, not everyone is familiar with Lorem Ipsum and that can lead to confusion. I can’t tell you how many times clients have asked me why their website is in another language!
There are other placeholder text alternatives like Hipster Ipsum, Zombie Ipsum, Bacon Ipsum, and many more. While often hilarious, these placeholder passages can also lead to much of the same confusion.
If you’re curious, this is Website Ipsum. It was specifically developed for the use on development websites. Other than being less confusing than other Ipsum’s, Website Ipsum is also formatted in patterns more similar to how real copy is formatted on the web today.
Question 2
This is just placeholder text. Don’t be alarmed, this is just here to fill up space since your finalized copy isn’t ready yet. Once we have your content finalized, we’ll replace this placeholder text with your real content.
Sometimes it’s nice to put in text just to get an idea of how text will fill in a space on your website.
Traditionally our industry has used Lorem Ipsum, which is placeholder text written in Latin. Unfortunately, not everyone is familiar with Lorem Ipsum and that can lead to confusion. I can’t tell you how many times clients have asked me why their website is in another language!
There are other placeholder text alternatives like Hipster Ipsum, Zombie Ipsum, Bacon Ipsum, and many more. While often hilarious, these placeholder passages can also lead to much of the same confusion.
If you’re curious, this is Website Ipsum. It was specifically developed for the use on development websites. Other than being less confusing than other Ipsum’s, Website Ipsum is also formatted in patterns more similar to how real copy is formatted on the web today.
Question 3
This is just placeholder text. Don’t be alarmed, this is just here to fill up space since your finalized copy isn’t ready yet. Once we have your content finalized, we’ll replace this placeholder text with your real content.
Sometimes it’s nice to put in text just to get an idea of how text will fill in a space on your website.
Traditionally our industry has used Lorem Ipsum, which is placeholder text written in Latin. Unfortunately, not everyone is familiar with Lorem Ipsum and that can lead to confusion. I can’t tell you how many times clients have asked me why their website is in another language!
There are other placeholder text alternatives like Hipster Ipsum, Zombie Ipsum, Bacon Ipsum, and many more. While often hilarious, these placeholder passages can also lead to much of the same confusion.
If you’re curious, this is Website Ipsum. It was specifically developed for the use on development websites. Other than being less confusing than other Ipsum’s, Website Ipsum is also formatted in patterns more similar to how real copy is formatted on the web today.
Question 4
This is just placeholder text. Don’t be alarmed, this is just here to fill up space since your finalized copy isn’t ready yet. Once we have your content finalized, we’ll replace this placeholder text with your real content.
Sometimes it’s nice to put in text just to get an idea of how text will fill in a space on your website.
Traditionally our industry has used Lorem Ipsum, which is placeholder text written in Latin. Unfortunately, not everyone is familiar with Lorem Ipsum and that can lead to confusion. I can’t tell you how many times clients have asked me why their website is in another language!
There are other placeholder text alternatives like Hipster Ipsum, Zombie Ipsum, Bacon Ipsum, and many more. While often hilarious, these placeholder passages can also lead to much of the same confusion.
If you’re curious, this is Website Ipsum. It was specifically developed for the use on development websites. Other than being less confusing than other Ipsum’s, Website Ipsum is also formatted in patterns more similar to how real copy is formatted on the web today.



