Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juliovedovatto/0a90b8167718617dcb3c6226758fc9f6 to your computer and use it in GitHub Desktop.
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.
<?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