Open a Divi Toggle or Accordion From the URL
Opens the Divi toggle or accordion item whose CSS ID matches the address hash (for example #shipping) and scrolls to it, so you can link straight to an answer.
Opens WPIDE on
Code
<script>
(function () {
function openTarget() {
var id = decodeURIComponent(window.location.hash.slice(1));
if (!id) { return; }
var target = document.getElementById(id);
var toggle = target && (target.classList.contains('et_pb_toggle') ? target : target.querySelector('.et_pb_toggle'));
if (!toggle) { return; }
if (toggle.classList.contains('et_pb_toggle_close')) {
var title = toggle.querySelector('.et_pb_toggle_title');
if (title) { title.click(); }
}
setTimeout(function () { toggle.scrollIntoView({ block: 'start', behavior: 'smooth' }); }, 300);
}
window.addEventListener('load', openTarget);
window.addEventListener('hashchange', openTarget);
})();
</script>
Notes
Give the toggle or accordion item a CSS ID in its Advanced tab, then link to page-url#that-id.
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.