Skip to content

Instantly share code, notes, and snippets.

@nickpelton
Last active July 15, 2017 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpelton/11146942 to your computer and use it in GitHub Desktop.
Save nickpelton/11146942 to your computer and use it in GitHub Desktop.
WP: wp_localize_script admin-ajax url
<?php
// Setup our data
$myDataArray = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
);
// 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