Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Created October 18, 2015 20:05
Show Gist options
  • Save yanknudtskov/82e0d6675073fe8782d6 to your computer and use it in GitHub Desktop.
Save yanknudtskov/82e0d6675073fe8782d6 to your computer and use it in GitHub Desktop.
<?php
// Using Script Debug to load non-minified scripts
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'my_awesome_script', "my_inc_dir/javascript_file{$min}.js", array( 'jquery' ), '0.1.0', true );
// Using script debug to log data in a javascript file
wp_localize_script( 'my_awesome_script', 'mas_obj', array(
// Set to true if debug is enabled, false otherwise
'is_debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? true : false,
) );
?>
<script type="text/javascript">
// Try and grab our object, if not make one.
var our_script_l10n = window.mas_obj || {};
// Check if debug is available/true
if ( our_script_l10n.is_debug ) {
// We have debug on for our script, so alert the user.
alert( 'Debug Works' );
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment