Creates an accessible mobile navigation toggle using aria-expanded and a CSS class, making it suitable for custom WordPress themes.
document.addEventListener('DOMContentLoaded', function () {
const toggle = document.querySelector('.menu-toggle');
const menu = document.querySelector('.mobile-menu');
if (!toggle || !menu) {
return;
}
toggle.addEventListener('click', function () {
const isOpen = toggle.getAttribute('aria-expanded') === 'true';
toggle.setAttribute('aria-expanded', String(!isOpen));
menu.classList.toggle('is-open', !isOpen);
});
});