Created
May 7, 2025 22:50
-
-
Save askwpgirl/faf5c622125709e21bcf27a66251dfae to your computer and use it in GitHub Desktop.
Add aria-current="page" for Elementor mega menu subitems
This file contains hidden or 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
<script>document.addEventListener('DOMContentLoaded', function () { | |
const currentUrl = window.location.origin + window.location.pathname; | |
const links = document.querySelectorAll('a[href]'); | |
links.forEach(link => { | |
const linkUrl = new URL(link.href); | |
const normalizedLink = linkUrl.origin + linkUrl.pathname; | |
if (normalizedLink === currentUrl) { | |
link.setAttribute('aria-current', 'page'); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment