Skip to content

Instantly share code, notes, and snippets.

@nickpelton
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpelton/11144971 to your computer and use it in GitHub Desktop.
Save nickpelton/11144971 to your computer and use it in GitHub Desktop.
WP: wp_localize_script
<?php
// Setup our data
$myDataArray = array(
'data' => array( // Add some data
'person' => array(
'name'=>'Nick',
'job' => 'Developer'
)
)
);
// Pass data to myscript.js on page load
wp_localize_script( "myScript", "myLocalizedData", $myDataArray );
// wp_localize_script( $handle, $objectName, $arrayOfValues );
// $handle - The enqueued script to place the data immedietly before
// $objectName - Name of the JS object that will hold the data
// $arrayOfValues - Data to pass to JS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment