Pass PHP Variables to Javascript in WordPress

Posted by & filed under Wordpress.

An easy developer snippet for themes In this example, I’m passing the Stylesheet Directory Uri (ref: wordpress) so the php function’s output is accessible in scripts.js. You can pass other variables to the vars object by adding more ‘key’ => ‘value’ pairs to the $variables_array. functions.php file $variables_array = array( ‘templateUrl’ => get_stylesheet_directory_uri() ); wp_enqueue_script(‘my-theme-script’,… Read more »