DMXzone Summer Sale: Save up to 51% with code DMXSUMMER26. Ends in

How to Pass PHP Data and Strings to JavaScript

Pass PHP Data and Strings to JavaScript in WordPress

It's good practice to put all your data in static strings in your PHP files. If you need to use some data in JavaScript later on, it's also good practice to put your data as data-* attributes in your HTML. But in some certain scenarios, you have no choice but to pass strings directly to your JavaScript code.

If you are including a JavaScript library, and you've found yourself initializing a JavaScript object inside your header.php then assigning data to its properties, then this article is for you.

This article will teach you on how to properly pass PHP data and static strings to your JavaScript library.

Comments

Be the first to write a comment

You must me logged in to write a comment.