-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load scripts with
wp_enqueue_script_module
- Loading branch information
Showing
1 changed file
with
5 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you manage "wp_localize_script", this still requires "wp_enqueue_script" to be in place.
Or what's the best option to have translatable strings in your JS?
52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@silverliiv I'm not entirely sure what you're asking?
52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change of "wp_enqueue_script" into "wp_enqueue_script_module" the "wp_localize_script" is not functioning correctly anymore, as it requires the "wp_enqueue_script" handler. And if you want to translate strings in WordPress for the JS to use them in your codebase, I found that wp_localize_script does that in great fashion.
52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure, I haven't had any issues with
wp_localize_script
myself.52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try and make it more clear.
// Using it like this, does execute the wp_localize_script
// Using it like this, does not execute the wp_localize_script
I'd say my theme setup is quite simple, nothing else should get on the way of it.
ChatGPT states: When working with WordPress, the wp_enqueue_script_module function is used to enqueue JavaScript modules (using type="module"). However, wp_localize_script, a function commonly used to pass PHP data to JavaScript, is not directly compatible with module scripts because it was designed to work with traditional scripts.
So my guess is, that it's intended not to work with wp_enqueue_script_module. My question was, what's your workaround for that?
52038c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to be supported at the moment: https://core.trac.wordpress.org/ticket/60234