") add_action('wp_enqueue_scripts', function () { // Register a handle and print inline JS in the footer on every page wp_register_script('sd-menu-start-offset', false, [], null, true); wp_enqueue_script('sd-menu-start-offset'); $js = <<<'JS' (function () { var isMobile = window.matchMedia('(max-width: 1024px)').matches; if (!isMobile) return; if (window.location.hash) return; if (window.scrollY > 10) return; window.addEventListener('load', function () { var menuWrap = document.querySelector('#sd-drop-menu'); if (!menuWrap) return; var offset = 0; var header = document.querySelector('.elementor-location-header, header.site-header, .elementor-sticky--active'); if (header) { var cs = window.getComputedStyle(header); if (cs.position === 'fixed' || cs.position === 'sticky') { offset += header.getBoundingClientRect().height; } } var adminBar = document.getElementById('wpadminbar'); if (adminBar) { var abCS = window.getComputedStyle(adminBar); if (abCS.position === 'fixed') { offset += adminBar.getBoundingClientRect().height; } } offset += 20; var rect = menuWrap.getBoundingClientRect(); var targetTop = rect.top + window.scrollY - offset; if (targetTop > 0) { window.scrollTo({ top: targetTop, behavior: 'smooth' }); } }); })(); JS; wp_add_inline_script('sd-menu-start-offset', $js);