Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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