Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.
// 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
You can’t perform that action at this time.