Pass PHP variable to javascript
Best practice method Have a look at wp_localize_script, which is meant to do exactly that. But it does require previous usage of wp_enqueue_scripts, hence you will need to move your JS to a separate file indeed. It will be worth those few minutes of effort though, for sure. function wpse_96370_scripts() { if ( is_single() ) … Read more