Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created October 21, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpmark/e75171c627a5bab395b0 to your computer and use it in GitHub Desktop.
Save wpmark/e75171c627a5bab395b0 to your computer and use it in GitHub Desktop.
Enqueuing a localised script in WordPress
<?php
function myplugin_enqueue_scripts() {
/* hand the js for deleting uploads by ajax */
wp_enqueue_script(
'myplugin-utilities-ajax',
plugins_url( '/assets/js/nameofjsfile.js', __FILE__ ),
array( 'jquery' ),
'1.0.0',
true
);
wp_localize_script(
'nxtgen-utilities-ajax',
'myplugin_js', // this is the name that prefixes the ajaxurl in our js file
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);
}
add_action( 'wp_enqueue_scripts', 'myplugin_enqueue_scripts' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment