Last active
September 27, 2016 21:41
-
-
Save igmoweb/fe669ba5f63f7ac2cab6ffc4330efa67 to your computer and use it in GitHub Desktop.
It avoids minification and concatenation for Divi assets (assets slugs must be filled)
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 | |
if ( $is_divi_builder_loaded ) { | |
// This won't activate minification while Divi builder is loaded in front | |
add_filter( 'wp_hummingbird_is_active_module_minify', '__return_false', 50 ); | |
} | |
// Don't minify Divi assets in any case | |
add_filter( 'wphb_minify_resource', function( $minify, $handle, $type ) { | |
$divi_scripts = array( 'divi-js-1', 'divi-js-2', 'divi-js-3' ); | |
$divi_styles = array( 'divi-css-1', 'divi-css-2' ); | |
if ( ( in_array( $handle, $divi_scripts ) && 'scripts' === $type ) || ( in_array( $handle, $divi_styles ) && 'styles' === $type ) ) { | |
return false; | |
} | |
return $minify; | |
}, 10, 3 ); | |
// Don't combine Divi assets in any case | |
add_filter( 'wphb_combine_resource', function( $combine, $handle, $type ) { | |
$divi_scripts = array( 'divi-js-1', 'divi-js-2', 'divi-js-3' ); | |
$divi_styles = array( 'divi-css-1', 'divi-css-2' ); | |
if ( ( in_array( $handle, $divi_scripts ) && 'scripts' === $type ) || ( in_array( $handle, $divi_styles ) && 'styles' === $type ) ) { | |
return false; | |
} | |
return $combine; | |
}, 10, 3 ); | |
// Last step is to remove Divi assets from minification files list in wp-admin | |
// so users cannot switch Divi assets to be minified/combined again or move them to header/footer | |
add_filter( 'wphb_minification_display_enqueued_file', function( $display, $item, $type ) { | |
$divi_scripts = array( 'divi-js-1', 'divi-js-2', 'divi-js-3' ); | |
$divi_styles = array( 'divi-css-1', 'divi-css-2' ); | |
if ( ( in_array( $item['handle'], $divi_scripts ) && 'scripts' === $type ) || ( in_array( $item['handle'], $divi_styles ) && 'styles' === $type ) ) { | |
return false; | |
} | |
return $display; | |
}, 10, 3 ); | |
add_action( 'plugins_loaded', function() { | |
remove_action( 'after_setup_theme', 'wphb_divi_after_setup_theme' ); | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment