Skip to content

Instantly share code, notes, and snippets.

@erikmolenaarnl
Created November 15, 2024 13:36
Show Gist options
  • Save erikmolenaarnl/cf9d480efb8419d07fbb0bdf329418e6 to your computer and use it in GitHub Desktop.
Save erikmolenaarnl/cf9d480efb8419d07fbb0bdf329418e6 to your computer and use it in GitHub Desktop.
Exclude Mediavine JS script from being optimized (e.g. minified, combined or deferred) by the SG Optimizer plugin
/**
* Exclude Mediavine JS script from being optimized (e.g. minified, combined or deferred) by the SG Optimizer plugin
*/
add_filter( 'sgo_js_minify_exclude', 'emd_exclude_mv_scripts_handles' );
add_filter( 'sgo_javascript_combine_exclude', 'emd_exclude_mv_scripts_handles' );
add_filter( 'sgo_js_async_exclude', 'emd_exclude_mv_scripts_handles' );
function emd_exclude_mv_scripts_handles( $exclude_list ) {
$exclude_list[] = 'mv-control-panel';
return $exclude_list;
}
// Additional fallback for JS IDs
add_filter( 'sgo_javascript_combine_exclude_ids', 'emd_exclude_mv_scripts_ids' );
function emd_exclude_mv_scripts_ids( $exclude_list ) {
$exclude_list[] = 'mv-script-wrapper-js';
return $exclude_list;
}
// Additional fallback filter for external JS paths
add_filter( 'sgo_javascript_combine_excluded_external_paths', 'emd_exclude_mv_scripts_external' );
function emd_exclude_mv_scripts_external( $exclude_list ) {
$exclude_list[] = 'scripts.mediavine.com';
return $exclude_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment