fix: always localize storefront-navigation script regardless of menu assignment#2212
Open
thisismyurl wants to merge 1 commit into
Open
Conversation
…ndheld menu is assigned
storefront-navigation.js is enqueued unconditionally, but
wp_localize_script() was called only inside the has_nav_menu('handheld')
conditional. When a handheld menu location exists but no menu is assigned
to it, has_nav_menu() returns false, storefrontScreenReaderText is never
defined, and the script throws:
ReferenceError: storefrontScreenReaderText is not defined
The l10n strings are static translated values that cost nothing to
output. Moving wp_localize_script() outside the conditional ensures the
global is always available whenever the script is enqueued.
The has_nav_menu() guard is not needed here — the JS uses the strings
for accessibility labels on any navigation it finds in the DOM,
regardless of whether a menu is formally registered via WP.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR simplifies how screen-reader strings are passed to the storefront-navigation script by inlining the localization call and removing the conditional wrapper.
Changes:
- Replaced a temporary localization array variable with an inline
wp_localize_script()call. - Removed the
has_nav_menu( 'handheld' )condition so the localized strings are always registered for the navigation script.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
storefront-navigation.jsis always enqueued, butwp_localize_script()was only called insideif ( has_nav_menu( 'handheld' ) ). When the handheld menu location is registered but no menu is assigned,has_nav_menu()returnsfalse, thestorefrontScreenReaderTextglobal is never defined, and the script throws a JavaScript error:This can happen on a fresh Storefront install before a menu is assigned to the handheld location, and on any setup where menus are managed outside of Appearance → Menus.
Before:
After:
The l10n strings are static translated values. There is no cost to outputting them whenever the script is enqueued. The
has_nav_menu()guard was protecting something that doesn't need protecting.Related to #2082
Development and testing assisted by AI. All code reviewed and verified manually.