Using the non-minified version of jQuery in WordPress

If you’re developing in WordPress, you’ll probably have define('SCRIPT_DEBUG', true); in your wp-config.php file, which ensures that WordPress does not load minified javascript files. Unfortunately, because of it’s large size a non-minified version of jQuery is not included in WordPress, which means debugging jQuery related issues can be a real pain. Thankfully, it’s easy to fix, and the code below can be easily be added to your custom developer plugin. The code simply checks which version of jQuery is currently registered, then deregisters it and re-registers Google’s unminified version.

if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
	add_action ('wp_enqueue_scripts', 'wpcs_init');
	add_action ('admin_enqueue_scripts', 'wpcs_init');
}

function wpcs_init() {
	global $wp_scripts;
	if (isset($wp_scripts->registered['jquery']->ver)) {
		$jquery_version = $wp_scripts->registered['jquery']->ver;
		wp_deregister_script ('jquery');
		wp_register_script ('jquery', "http://ajax.googleapis.com/ajax/libs/jquery/{$jquery_version}/jquery.js");
	}
}

Comments

  1. Thank you for this! It is working perfectly on the front end. I’m not sure if it will work on the administration panels anymore though, because you can’t deregister jQuery on the admin side anymore. There may be a workaround though.

Speak Your Mind

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.