Skip to content

Instantly share code, notes, and snippets.

@chriscct7
Last active February 23, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chriscct7/0f91db23bfba7bfb5522cff5098cbd3b to your computer and use it in GitHub Desktop.
Save chriscct7/0f91db23bfba7bfb5522cff5098cbd3b to your computer and use it in GitHub Desktop.
Remove conflicting styles/scripts from MI pages
<?php
/*
Plugin Name: Imagify Conflict Fix for MonsterInsights
Plugin URI:
Description: Fixes conflict with Imagify on MonsterInsights admin pages
Version: 1.0.0
Author: MonsterInsights Support Team
Author URI: https://www.monsterinsights.com
License:
License URI:
*/
function custom_monsterinsights_remove_conflicting_asset_files() {
// Get current screen.
$screen = get_current_screen();
// Bail if we're not on a MonsterInsights screen.
if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
return;
}
$styles = array();
$scripts = array();
$styles = array(
'imagify-sweetalert-core', // Imagify
'imagify-sweetalert', // Imagify
);
$scripts = array(
'imagify-promise-polyfill', // Imagify
'imagify-sweetalert', // Imagify
'imagify-chart', // Imagify
);
if ( ! empty( $styles ) ) {
foreach ( $styles as $style ) {
wp_dequeue_style( $style ); // Remove CSS file from MI screen
wp_deregister_style( $style );
}
}
if ( ! empty( $scripts ) ) {
foreach ( $scripts as $script ) {
wp_dequeue_script( $script ); // Remove JS file from MI screen
wp_deregister_script( $script );
}
}
}
add_action( 'admin_enqueue_scripts', 'custom_monsterinsights_remove_conflicting_asset_files', 9998 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment