WordPress Modal Menu Fix for Anchor Links in Twenty Twenty-Two Theme

The new block-based WordPress Twenty Twenty-Two theme was having an error for the modal pop-up/overlay navigation menu when using anchor links to an anchor location on the same page. Clicking the link would move the page to the new target anchor link location (behind the pop-up modal), however it would not shut the modal menu.

In searching for some code to fix the issue, there were support tickets for this issue on a number of other WordPress themes – but no clear fix.

In order to fix the issue without adding a code patch, the link can be entered without using the https:// prefix on the URL. e.g. Entering https://urlgoeshere…/#test would not close the pop-up, however entering just urlgoeshere…/#test closes the pop-up modal and the page lands on the desired anchored section.