Last active
July 15, 2017 13:15
-
-
Save nickpelton/11146942 to your computer and use it in GitHub Desktop.
WP: wp_localize_script admin-ajax url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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