Sometimes, it becomes necessary to edit core WordPress files directly, inside a non production environment, to better understand the behavior of the WordPress platform and pinpoint specific problems. By default, WordPress combines and compresses its JavaScript files to improve performance, but this can make it difficult to trace issues or make modifications.
This tutorial will guide you through the steps to disable these features, allowing you to work with the original, unminified files.
Editing wp-config.php directly to disable minification.
To disable script concatenation and compression, add the following lines to the wp-config.php
file:
define('CONCATENATE_SCRIPTS', false);
define('SCRIPT_DEBUG', true);
Code language: PHP (php)
Editing functions.php directly to disable minifications.
To disable script minification and concatenation via your theme’s functions.php
file, add the following code:
add_filter('script_loader_src', 'disable_minification', 10, 2);
add_filter('style_loader_src', 'disable_minification', 10, 2);
function disable_minification($src, $handle) {
if (strpos($src, '.min.') !== false) {
$src = str_replace('.min.', '.', $src);
}
return $src;
}
Code language: PHP (php)
Additional considerations
Direct modification of core WordPress files is generally discouraged due to the following reasons:
- Changes will be overwritten during updates.
- It may lead to unexpected behavior if not executed properly.
Preferably, use hooks, filters, or plugins to implement changes. For those needing to directly edit JavaScript files, creating a custom plugin or theme to include the custom scripts is advised.
Loading comments...