• Resolved Mastafu Design

    (@mastafu)


    Hi, can you help me with this problem.

    I want to optimize my website by removing these js and css from certain pages. Usually this code works, but not this time.

    
    	function unregister_non_woocommerce_styles_scripts() {
    	    error_log('Funkcja unregister_non_woocommerce_styles_scripts zosta?a wywo?ana');
    	    // Sprawd?, czy to nie jest strona WooCommerce
    	   // if ( !is_woocommerce() && !is_cart() && !is_checkout() ) {
    	        // Wyrejestruj CSS
    	        wp_deregister_style('eb-pro-sso-public-style-css');
    	        wp_deregister_style('eb-pro-woo-int-public-css-css');
    	        wp_deregister_style('dashicons-css');
    	        wp_deregister_style('edwiserbridge_font_awesome-css');
    	        wp_deregister_style('edwiserbridge-css');
    	        wp_deregister_style('wdmdatatablecss-css');
    	        wp_deregister_style('eb-public-jquery-ui-css-css');
    	        
    	        // Wyrejestruj JS
    	        wp_dequeue_script('cookie-law-info-ccpa-js');
    	        wp_dequeue_script('eb-pro-sso-public-script-js');
    	        wp_dequeue_script('eb-pro-woo-int-public-js-js');
    	        wp_dequeue_script('jquery-ui-core-js');
    	        wp_dequeue_script('jquery-ui-mouse-js');
    	        wp_dequeue_script('jquery-ui-resizable-js');
    	        wp_dequeue_script('jquery-ui-draggable-js');
    	        wp_dequeue_script('jquery-ui-controlgroup-js');
    	        wp_dequeue_script('jquery-ui-checkboxradio-js');
    	        wp_dequeue_script('jquery-ui-button-js');
    	        wp_dequeue_script('jquery-ui-dialog-js');
    	        wp_dequeue_script('edwiserbridge-js');
    	        wp_dequeue_script('edwiserbridge-ui-block-js');
    	        wp_dequeue_script('wdmdatatablejs-js');
    	 //   }
    	}
    	add_action('wp_enqueue_scripts', 'unregister_non_woocommerce_styles_scripts', 100);
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @mastafu

    Regarding your query about optimizing your website by removing certain JS and CSS from specific pages, our team has identified an issue in the code you provided. The issue lies in the inclusion of “-css” and “-js” at the end of each script slug, which is added by default in WordPress. To resolve this, you need to remove the last “-css” or “-js” from the slugs.

    Please find the corrected code below:

    function unregister_non_woocommerce_styles_scripts() {
        error_log('Funkcja unregister_non_woocommerce_styles_scripts zosta?a wywo?ana');
        // Sprawd?, czy to nie jest strona WooCommerce
       // if ( !is_woocommerce() && !is_cart() && !is_checkout() ) {
            // Wyrejestruj CSS
            wp_deregister_style('eb-pro-sso-public-style');
            wp_deregister_style('eb-pro-woo-int-public');
            wp_deregister_style('dashicons');
            wp_deregister_style('edwiserbridge_font_awesome');
            wp_deregister_style('edwiserbridge');
            wp_deregister_style('wdmdatatablecss');
            wp_deregister_style('eb-public-jquery-ui-css');
            
            // Wyrejestruj JS
            wp_dequeue_script('cookie-law-info-ccpa');
            wp_dequeue_script('eb-pro-sso-public-script');
            wp_dequeue_script('eb-pro-woo-int-public-js');
            wp_dequeue_script('jquery-ui-core');
            wp_dequeue_script('jquery-ui-mouse');
            wp_dequeue_script('jquery-ui-resizable');
            wp_dequeue_script('jquery-ui-draggable');
            wp_dequeue_script('jquery-ui-controlgroup');
            wp_dequeue_script('jquery-ui-checkboxradio');
            wp_dequeue_script('jquery-ui-button');
            wp_dequeue_script('jquery-ui-dialog');
            wp_dequeue_script('edwiserbridge');
            wp_dequeue_script('edwiserbridge-ui-block');
            wp_dequeue_script('wdmdatatablejs');
    //   }
    }
    add_action('wp_enqueue_scripts', 'unregister_non_woocommerce_styles_scripts', 100);

    If you have any further questions or need additional assistance, please feel free to ask.

    Thanks,

    Team Edwiser

    Thread Starter Mastafu Design

    (@mastafu)

    thx, that was the case.

    Thread Starter Mastafu Design

    (@mastafu)

    solved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Optimization with deregister and dequeue’ is closed to new replies.