Created
October 21, 2015 18:48
-
-
Save wpmark/e75171c627a5bab395b0 to your computer and use it in GitHub Desktop.
Enqueuing a localised script in WordPress
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 | |
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