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)
- Theme Javascript.php Overwritten Nightly [closed]
- Menu jumping when calling it via PHP
- How to get javascript slider to work! [closed]
- 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
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- Using page-id-{ID} from body_class() in local dev, versus live staging
- Does the textdomain have to be the theme’s name?
- Custom theme, contact form 7 & fast secure form doesn’t work
- Enqueued JavaScript is not working
- Why set a second parameter in the translate function?
- Javascipt issue on custom theme
- 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
- How can I wrap all blog posts image with
- White screen when attaching css to function.php
- WordPress theme resource won’t load over VPN
- 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]
- Translate a theme with a PO file
- How do I implement jPanelMenu?
- loading javascript after jquery is loaded
- 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
- getBoundingClientRect() showing different values on load vs scroll
- wordpress script_loader_tag in function.php
- how to unlocalize theme/plugin?
- How to diagnose wp-env environment problem
- how can i remove js file from my footer in wordpress
- How to properly use AWS SES for a contact form?
- 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?
- Theme starter content translation is not working
- Ajax Comment Upvotes – Votes don’t always register
- Infinite scroll without plugin using ajax
- Menu names not getting translated
- Customizer Image-Picker Preview Not Working
- 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
- Flexslider not working for my custom theme WordPress
- 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
- Can’t attach Javascript to theme
- Passing a location-dependent array via wp_localize_script within a shortcode
- enqueue script if page is not equal to
- wp_deregister_script was called incorrectly
- Paginated WP_Query doesn’t return 404’s, even when posts don’t exist
- Display Today’s date outside the loop?
- Using wp_enqueue_script with social media buttons?
- How to convert that page to a wordpress template? [closed]
- wp_enqueue_script causes page to vanish
- WordPress Subpages Fancybox Trouble
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- What is The Best Way to Make Parallax header effect for wordpress theme ?? pure CSS or using JavaScript? [closed]
- Javascript as Jquery Function Call?
- WP site makes mobile browser crash for high memory usage
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- How to get the value entered in the input field in wordpres
- 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
- Is there any halfway decent documentation on the wp.media JS class?
- WordPress Includes mejs 404 error
- Smooth Scrolling Animation of Image Between Two Containers (Elementor) Using JavaScript and GSAP
- Dashboard and Site Language only partially translated (in own theme)
- How to add group-row to InnerBlock template?
- Javascript localization doesn’t load. How to Internationalize javascript without plugin?