jester1979
1/27/2015 - 8:16 PM

Javascript vars

Javascript vars

add_action( 'wp_head', 'append_header_js_vars' );
/**
 * Append some handy dandy JS vars to the head
 *
 * Adds necessary code to start the PE-application (on document ready),
 * with the WP_DEBUG boolean as a parameter.
 *
 * @since 1.0.0
 */
function append_header_js_vars() {

	$params = array(
		'stylesheet_uri'	=> get_stylesheet_directory_uri(),
		'template_uri'		=> get_template_directory_uri(),
		'ajax_uri'			=> admin_url( 'admin-ajax.php' ),
	);

	?>
	<script>
	
		var site_params = <?php json_encode( $params ); ?>;
			
	</script>
	<?php		
}