Created
August 8, 2023 23:12
-
-
Save stefanmm/02c8895185d48e1f3f402934cf87223f to your computer and use it in GitHub Desktop.
WP 6.3 - Open "Details" block automatically on page load based on URL hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First, set a class name inside the "Details" accordion block (because we do not have ability to set the ID) | |
// If multiple elements with the same class name are detected, the first one will be triggered | |
// Append that class name after the page URL, like so: site.domain/page/#classname | |
if(window.location.hash) { | |
var hash = window.location.hash; | |
var el = document.getElementsByClassName(hash.slice(1))[0]; | |
if(!el.hasAttribute('open')){ | |
el.setAttribute('open', ''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment