Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created October 15, 2015 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/bb94f210cbfbc6903d8b to your computer and use it in GitHub Desktop.
Save tommcfarlin/bb94f210cbfbc6903d8b to your computer and use it in GitHub Desktop.
[WordPress] Using SCRIPT_DEBUG To Debug JavaScript Files in WordPress
<?php
// Add define('SCRIPT_DEBUG', true); to wp-config.php to enable loading of non-minified,
// non-concatenated scripts and stylesheets.
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
if ( ! empty( $GLOBALS['wp_version'] ) ) {
$develop_src = false !== strpos( $GLOBALS['wp_version'], '-src' );
} else {
$develop_src = false;
}
define( 'SCRIPT_DEBUG', $develop_src );
}
<?php
/* If we're debugging JavaScript files, define the
* suffix for the file to load the proper version.
*/
$js_suffix = ( defined( 'SCRIPT_DEBUG' ) ) ? '.min.js' : '.js';
wp_enqueue_script(
'acme-demo-javascript',
plugin_dir_url( dirname( __FILE__ ) ) . 'admin/assets/js/large-button' . $js_suffix,
array( 'jquery' ),
'1.0.0',
false
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment