Skip to content

Instantly share code, notes, and snippets.

@tiendungdev
Forked from devinsays/performance.php
Created December 9, 2024 13:31
Show Gist options
  • Select an option

  • Save tiendungdev/edca7fd4e26f077e099d2c4c1bfc57f6 to your computer and use it in GitHub Desktop.

Select an option

Save tiendungdev/edca7fd4e26f077e099d2c4c1bfc57f6 to your computer and use it in GitHub Desktop.

Revisions

  1. @devinsays devinsays created this gist Nov 19, 2021.
    74 changes: 74 additions & 0 deletions performance.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    <?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();