When adding scripts to WordPress, you will inevitably run into a small, but painful, issue of localization. Localizing a plugin or theme is relatively straightforward, but JavaScript presents its own difficulties since we can’t easily call the PHP functions necessary (which is one reason authors embed JavaScript in PHP files). Since embedding JavaScript in PHP files is never a good technique, we use localization to save the day. With JavaScript localization, you can use PHP magic to build your localized strings, and then use JavaScript to read/parse those strings. What you do with them is only limited to your imagination. Furthermore, if you display anything with JavaScript, chances are your users will want the strings to be localized. Fortunately, WordPress provides the ultra-handy wp_localize_script function. wp_localize_script The wp_localize_script takes three arguments: handle object_name l10n Handle The handle argument will be the same handle you use for your script name. For […]
[Continue Reading...]