Skip to content

Instantly share code, notes, and snippets.

@jester1979
Created January 27, 2015 20:16
Show Gist options
  • Save jester1979/fd19fdd9d56f0c19d4dd to your computer and use it in GitHub Desktop.
Save jester1979/fd19fdd9d56f0c19d4dd to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment