-
-
Save tiendungdev/edca7fd4e26f077e099d2c4c1bfc57f6 to your computer and use it in GitHub Desktop.
Dequeue scripts and styles
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 | |
namespace DevPress\Frontend; | |
/** | |
* Class Performance | |
* | |
* @package DevPress\Performance | |
*/ | |
class Performance { | |
/** | |
* @var Performance | |
*/ | |
protected static $instance; | |
/** | |
* Ensures only one instance of the Performance is loaded or can be loaded. | |
* | |
* @return Performance - Main instance. | |
*/ | |
public static function instance() { | |
if ( is_null( self::$instance ) ) { | |
self::$instance = new self(); | |
} | |
return self::$instance; | |
} | |
public function __construct() { | |
add_action( 'wp_print_scripts', [ $this, 'remove_scripts' ], 100 ); | |
add_action( 'wp_enqueue_scripts', [ $this, 'remove_styles' ], 100); | |
} | |
/** | |
* Remove scripts that have been enqueued by other plugins. | |
*/ | |
public function remove_scripts() { | |
if ( is_front_page() ) { | |
wp_dequeue_script( 'popup-maker-site' ); | |
wp_dequeue_script( 'wc-add-to-cart' ); | |
wp_dequeue_script( 'woocommerce' ); | |
wp_dequeue_script( 'wc-cart-fragments' ); | |
wp_dequeue_script( 'wp-embed' ); | |
wp_dequeue_script( 'jquery-payment' ); | |
wp_dequeue_script( 'sv-wc-payment-gateway-payment-form-v5_10_7' ); | |
} | |
if ( is_page( 'otherpage' ) ) { | |
wp_dequeue_script( 'popup-maker-site' ); | |
} | |
} | |
/** | |
* Remove styles that have been enqueued by other plugins. | |
*/ | |
function remove_styles() { | |
if ( is_front_page() ) { | |
wp_dequeue_style( 'popup-maker-site' ); | |
wp_dequeue_style( 'wp-block-library' ); | |
wp_dequeue_style( 'wc-block-vendors-style' ); | |
wp_dequeue_style( 'wc-block-style' ); | |
wp_dequeue_style( 'automatewoo-referrals' ); | |
wp_dequeue_style( 'sv-wc-payment-gateway-payment-form-v5_10_7' ); | |
wp_dequeue_style( 'metorik-css' ); | |
wp_dequeue_style( 'woocommerce-inline' ); | |
} | |
if ( is_page( 'otherpage' ) ) { | |
wp_dequeue_style( 'popup-maker-site' ); | |
} | |
} | |
} | |
Frontend\Performance::instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment