can someone explain me what wp_localize_script()
do?
I don’t understand what it does in the first place even I have read it in the WP Codex.
Leave a Reply
You must be logged in to post a comment.
can someone explain me what wp_localize_script()
do?
I don’t understand what it does in the first place even I have read it in the WP Codex.
You must be logged in to post a comment.
It lets you use PHP data in the client by printing out a JavaScript object. From the Codex:
You use like so:
This will print an object in JavaScript:
Now in the client you can access that data:
It’s very useful when you’re building plugins so you can separate your client from your server logic instead of mixing JS and PHP all in the same file.