Skip to content

Instantly share code, notes, and snippets.

@garyc40
Created October 3, 2012 14:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save garyc40/3827389 to your computer and use it in GitHub Desktop.
Save garyc40/3827389 to your computer and use it in GitHub Desktop.
Enqueue & localize JS in WordPress
// embed the javascript file that makes the AJAX request
wp_enqueue_script( 'my-ajax-request', plugin_dir_url( __FILE__ ) . 'js/ajax.js', array( 'jquery' ) );
// declare the URL to the file that handles the AJAX request (wp-admin/admin-ajax.php)
wp_localize_script( 'my-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment