WordPress currently uses the gettext
feature which is available in php
but unfortunately not in Javascript
.
I have searched this matter on the web and have come up with this trick. But there is a problem as the php file needs to be called through WordPress
system for the gettext
feature to kick in.
I’m wondering if there is any way to call a php file inside WordPress so we can use the built-in functions and variables?
Or if anyone can come up with a better solution, that’d be super.
Leave a Reply
You must be logged in to post a comment.
WordPress has a nice function mainly for that wp_localize_script
To use it first queue your script:
then create an array of strings you want to localize:
and call it using wp_localize_script
then you can access it in the page using JavaScript like this:
…
you get the Idea.