This is a workaround for an annoying Elementor behavior…
If you embed a WordPress Menu widget in a Popup and that menu contains anchor links, the popup won’t natively close when an anchor link is clicked (and you’re on the same page as the target element).
For example, if my menu item “About” is linked to #about
, clicking that menu item will scroll to the right spot, but the popup will stay open. This is a known issue.
Dropping this into the Custom Code section (and configuring it to load on whatever pages you need) will resolve this annoyance.