Referencing files in JavaScript in WordPress Plugin

Use wp_localize_script. function pr_add_link_sound () { //Register the script first wp_register_script(‘add_sound’, plugins_url( ‘add_sound.js’, __FILE__ ), array(‘jquery’), ”, true); //Localize the sound file url to use in the script $args = array( ‘sound1’ => plugins_url( ‘sound.mp3’, __FILE__ ), ); wp_localize_script( ‘add_sound’, ‘PRSound’, $args ); //Enqueue the script wp_enqueue_script(‘add_sound’); } You can reference the sound in the … Read more