Created
December 6, 2018 18:34
-
-
Save juliovedovatto/0a90b8167718617dcb3c6226758fc9f6 to your computer and use it in GitHub Desktop.
Autoptimize is a exelente wordpress plugin, but it seems it ignore the blacklist from "Exclude scripts from Autoptimize" option. The plugin persists to minify and combine, instead of leaving it as it is. So I found this filter, that I can check the url and check agains the blacklist. If the js item is blacklisted, Autoptimize will skip it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// theme functions.php | |
add_filter('autoptimize_filter_js_minify_excluded', function ($condition, $url) { | |
if (!$blacklist = get_option('autoptimize_js_exclude', false)) | |
return true; | |
$blacklist = array_filter(array_map('trim', explode( ',', $blacklist))); | |
return count(array_filter($blacklist, function ($match) use ($url) { | |
return false !== strpos($url, $match); | |
})) === 0; | |
}, PHP_INT_MAX, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment