Indeed, wp_localize_script()
is simple, it just adds quotes around the values and escapes the content, expecting all of them to be strings.
However, there is the l10n_print_after
key of the array, which will be printed without any interference at all. It can be used to execute arbitrary code after the strings are passed. You can use it to pass your extra data.
$data = array(
'layout_config' => {
'ls' : {'sb1': 1}
}
);
$reshuffled_data = array(
'l10n_print_after' => 'my_localized_data=" . json_encode( $data ) . ";'
);
wp_localize_script('my-script-handle', 'my_localized_data', $reshuffled_data);
You will end up with code like this:
var my_localized_data = {}; // What is left of your array
my_localized_data = {'layout_config': {'ls': {'sb1': 1}}}; // From l10n_print_after
Related Posts:
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How to Change CSS Variable value in Theme Customizer Live Preview
- How to correctly add JQuery in a WP theme?
- Including Javascript options
- jQuery not available to other scripts
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- My jQuery is enqueued properly. So why isn’t it working?
- How to enqueue scripts properly with ES6 webpack?
- change background image on scroll
- How would I get this to work – send to post from thick box
- Set start page depending on screen width [closed]
- Theme now uses require.js and enqueue script no longer works
- can’t add EVENT LISTENER to a element
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- What is the preferred way to add custom javascript files to the site?
- How to create .pot files with POedit?
- When to use _e and __ for the translation?
- What is a Theme textdomain?
- How to include jQuery and JavaScript files correctly?
- Proper, exhaustive documentation for wp.editor etc
- How to concatenate inside the _e() function the right way?
- Is there a way to set the order of wp_footer hooked functions?
- Google Maps not displaying in wordpress using Google Maps Javascript API
- Trigger Customizer saving process with Javascript only
- How to alter the text of the post “Excerpt” box label in WordPress post editor?
- What is the purpose of an extra file for translation?
- Change text of twentyseventeen_edit_link()
- Theme elements not translating
- Should we localize custom-made themes / plugins?
- Help with “text domain”, comments_form in WordPress theme
- wp_enqueue_script being ignored in custom theme
- WordPress Customizer Control with React
- Prevent WordPress updates from overriding custom language translations?
- Translation-readiness of Koi theme
- using wordpress without javascript
- My custom theme does not load the translations
- Unhook jQuery from WooCommerce via `functions.php`? [closed]
- Fancy-box Esay wordpress plugin fails to work on Multilingual site
- WP 3.1 upgrade breaks AutoFocus+ theme
- Translation Issue with WordPress Theme Check in comment_form function
- JavaScript Change focus to password field login page being reset
- Difficulty loading jQuery with wp_enqueue_script
- My javascript jquery won’t work?
- Default string not appearing want to translate
- Single page site with history.js
- Implementing FancyBox
- Should I change text-domain of TGM library inside theme?
- Use second time navigation.js in underscores [closed]
- Single translation for many locales
- Menu jumping when calling it via PHP
- Set parent theme language with custom .mo files
- Theme Customizer not loading JS for live preview
- Post thumbnail to append post content via ajax click event
- Does the textdomain have to be the theme’s name?
- Enqueued JavaScript is not working
- How to make javascript work on theme options page
- How to register and enqueue JavaScript files without breaking plugin dependencies?
- wp_enqueue_script not working?
- JQuery undefined and Stylesheet loads in bottom along with js files
- Weirdness in jQuery supplied with WordPress
- pass wordpress template directory into ajax url call
- theme-independent CSS/JS files
- Do translation functions like __e() have to take strings in English in themes?
- jQuery from parent theme loaded with many other scripts in a single min.js file
- Javascript development in Custom Themes
- Translate a child theme with pure PHP and gettext
- Trouble in enquing all js files under certain directory
- add jquery file if a certain page is included
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- How do I implement jPanelMenu?
- MapPress Easy Google Map in Jquery Tabs Problem
- Cart displayed above header
- enqueuing external and internal js and css in wordpress did not work with owl.js animate.css
- I don’t think WordPress is loading jquery or bootstrap js
- How to diagnose wp-env environment problem
- how can i remove js file from my footer in wordpress
- Embedding CodePen Calorie Script – jquery error
- WordPress theme doesn’t read my translations from pt_BR.po file
- How to load jQuery with Ajax in WP version 5.3.2?
- Infinite scroll without plugin using ajax
- Does any JavaScript file load automatically for index.php file?
- how to add jquery to wordpress
- Any way to permanently translate themes?
- jQuery conflict in WordPress, works fine in HTML
- FitVid not working for iframes on particular theme install
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- WordPress custom jquery not found
- Passing a location-dependent array via wp_localize_script within a shortcode
- Paginated WP_Query doesn’t return 404’s, even when posts don’t exist
- Using wp_enqueue_script with social media buttons?
- How to convert that page to a wordpress template? [closed]
- WordPress Subpages Fancybox Trouble
- What is The Best Way to Make Parallax header effect for wordpress theme ?? pure CSS or using JavaScript? [closed]
- Javascript as Jquery Function Call?
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- How react js and other Javascript Technologies works on WordPress plugin?
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified