Open Only One Details Block at a Time
Makes neighboring Details blocks behave like an accordion: opening one question closes the others in the same group, which keeps long FAQs tidy.
Opens WPIDE on
Code
document.addEventListener('toggle', function (e) {
var details = e.target;
if (!details.matches || !details.matches('details.wp-block-details') || !details.open) { return; }
var parent = details.parentElement;
if (!parent || parent.classList.contains('wpide-multi-open')) { return; }
Array.prototype.forEach.call(parent.children, function (sibling) {
if (sibling !== details && sibling.matches('details.wp-block-details') && sibling.open) { sibling.open = false; }
});
}, true);
Notes
Applies to Details blocks that sit next to each other in the same parent block. Add the class wpide-multi-open to the parent to allow several open at once.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.