yan-k
10/18/2015 - 8:05 PM

wordpress-script-debugging.php

<?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>