Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1319083
    fatheaddrummer
    Participant

    Hello Awesome Support Team,

    I would like to exclude my product page from autoptimize: https://www.diamond-precision-studio.com/product/trance-dance-cd-mix/

    But it doesn’t work. I am using this code to this!

    add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
    function my_ao_noptimize() {
    	if ((strpos($_SERVER['REQUEST_URI'],'woocommerce')!==false) || if (strpos($_SERVER['REQUEST_URI'],'request-free-mixdown-preview')!==false)) {
    		return true;
    	} else {
    		return false;
    	}
    }

    The code works fine on the other page (request-free-mixdown-preview).
    I have the feeling that it doesn’t work because the product page is not an actual page?

    Could you help me out? Thank you so much!
    Best, Christian

    #1319726
    Rue Nel
    Moderator

    Hello Christian,

    Thanks for writing in! Instead of getting the request_uri, you can use the WooCommerce conditional tags (https://docs.woocommerce.com/document/conditional-tags/) so that you can target all the product pages. Please have your code updated and make use of this code:

    add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
    function my_ao_noptimize() {
    	if ( is_product() ) {
    		return true;
    	} else {
    		return false;
    	}
    }

    Hope this helps. Please let us know how it goes.

    #1320158
    fatheaddrummer
    Participant

    Hi there,

    Thank you so much for your awesome support!
    This is what I added in the code! I also need a single page to be excluded, that’s why I tried to combine them, but unfortunately the product page still is NOT excluded…

    What have I done wrong?

    add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
    function my_ao_noptimize() {
    	if (
    	  (strpos($_SERVER['REQUEST_URI'],'request-free-mixdown-preview')!==false) ||
    	  ( is_product() ){
    		return true;
    	} else {
    		return false;
    	}
    }

    Also I would like to exclude all woocommerce pages…
    Thank you so much!
    Best, Christian

    #1320201
    Thai
    Moderator

    Hi There,

    Please update your code to this:

    add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
    function my_ao_noptimize() {
    	if ( strpos($_SERVER['REQUEST_URI'],'request-free-mixdown-preview') !== false 
    		|| is_cart()
    		|| is_woocommerce()
    		|| is_checkout()
    		|| is_account_page() ) {
    		return true;
    	} else {
    		return false;
    	}
    }

    Hope it helps 🙂

    #1320214
    fatheaddrummer
    Participant

    Thank you so much!
    You’re awesome!!

    Best, Christian

    #1320234
    Thai
    Moderator

    If you need anything else please let us know.

  • <script> jQuery(function($){ $("#no-reply-1319083 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>