Forked from wpmark/wp-enqueue-localised-script.php
Created
November 16, 2019 14:34
-
-
Save davenaylor/1842ad5f1b16e27bc6f5fdb80a11e22a to your computer and use it in GitHub Desktop.
Enqueuing a localised script in WordPress
This file contains hidden or 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