• Resolved devcri

    (@devcri)


    For SEO Reasons I dequeue WooCommerce Styles and Scripts outside of the WooCommerce Shop with the following script in functions.php:

    add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
    
    function child_manage_woocommerce_styles() {
    	//remove generator meta tag
    	remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
    	
    	//first check that woo exists to prevent fatal errors
    	if ( function_exists( 'is_woocommerce' ) ) {
    		//dequeue scripts and styles
    		if ( !is_woocommerce() && !is_shop() && !is_product_category() && !is_product_tag() && !is_product() && !is_cart() && !is_checkout() && !is_account_page() && !is_wc_endpoint_url() ) {
    			wp_dequeue_style( 'woocommerce-layout' );
    			wp_dequeue_style( 'woocommerce-smallscreen' );
    			wp_dequeue_style( 'woocommerce-general' );
    			wp_dequeue_script( 'wc-add-to-cart' );
    			wp_dequeue_script( 'wc-cart-fragments' );
    			wp_dequeue_script( 'woocommerce' );
    			wp_dequeue_script( 'jquery-blockui' );
    			wp_dequeue_script( 'jquery-placeholder' );
    		}
    	}
    }

    However I am not able to identify the taxonomy or category pages with these conditional tags. If I deactivate the add_action call the taxonomy page works fine as it doesn’t dequeue the styles and scripts.

    Is there an other conditional tag to identify taxonomy or product category pages?

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @devcri,

    Did you have a chance to try is_product_taxonomy()? It includes both build-in product taxonomies (like attributes, categories, etc) and custom ones added through other extensions. By default is_product_taxonomy() should be covered by the is_woocommerce() call, but if there are any filters changing the value of this one, you might want to try adding it separately too.

    Cheers!

    Thread Starter devcri

    (@devcri)

    Hi @madeincosmos,

    thank you for your feedback! I didn’t know about is_product_taxonomy(). I got the conditional tags from: https://docs.woocommerce.com/document/conditional-tags/ and there it isn’t mentioned.

    Unfortunately it doesn’t solve the problem. I tried including it in the statement:

    if ( !is_woocommerce() && !is_shop() && !is_product_category() && !is_product_tag() && !is_product() && !is_cart() && !is_checkout() && !is_account_page() && !is_wc_endpoint_url() && !is_product_taxonomy() ) { ...

    and also tried only this statement without the other conditional tags:

    if ( !is_product_taxonomy() ) {

    Seems that neither of the conditional tags can identify that it is on a product_taxonomy page.

    As soon as I comment out this line (deactivating the dequeue function) the taxonomy page looks perfect:

    //add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );

    But this also would mean that all the woocommerce styles and scripts are included on all pages. This hurts loading times, so I have to activate the function again.

    Cheers!

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @devcri,

    That sounds surprising! I just added the first snippet on my test site with WC 3.3.1 and it leaves WooCommerce styles still loaded on category pages. I also added another dummy snippet that adds a new line in the footer when I’m seeing a WooCommerce page:

    
    function is_a_woocommerce_page( ) {
      if ( is_woocommerce() ) {
        ?>
    	  <div>THIS IS A WOOCOMMERCE PAGE</div>
    	  <?
      }
      
    }
    add_action( 'wp_footer', 'is_a_woocommerce_page' );
    

    It appears on shop, category, and product pages alike.

    Have you checked what happens with Twenty Sixteen theme and only WooCommerce plugin enabled? You can use the Code Snippets plugin to test this snippet in isolation. If that solves the problem, enabling plugins and theme one by one should help you find out which one is changing the terms.

    By the way – this is a default category page generated by WooCommerce rather than using a shortcode, is that correct?

    Please let me know how that goes!

    Thread Starter devcri

    (@devcri)

    Hi @madeincosmos,

    I tried to change the if-statement to the following (according to your snippet):

    if ( !is_woocommerce() ) {

    But the taxonomy-page still is dequeuing the styles and scripts.

    And to your question: it is the default woocommerce taxonomy page (not using a shortcode. And it is not a woocommerce category). The shop page from WooCommerce by the way looks good (because it doesn’t dequeue the styles and scripts). You can see it here:
    https://www.russlandjournal.de/shop/ (it’s assigned to WooCommerce, but doesn’t use a shortcode)

    Unfortuantely switching the theme and deactivating all other plugins is not an option for me at the moment as it is a live site and I don’t have a test environment available at the moment.

    Thanks anyways for your support!

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @devcri,

    Thanks for checking! I just tested the same thing with a custom taxonomy created by WooCommerce Brands plugin, but it’s still recognized as a WooCommerce page. The last thing that comes to my mind is to make sure that the custom taxonomy is registered only for the product post type rather than default – but you probably know about this ??

    If this doesn’t help, you can try cloning your site using the WP Staging plugin – it will create a private test copy of the whole site in a subfolder.

    Cheers!

    Thread Starter devcri

    (@devcri)

    Hi @madeincosmos,

    thanks again for replying! I am not sure if I understand what you mean with “make sure that the custom taxonomy is registered only for the product post type rather than default”

    But I did this:

    In the WooCommerce Taxonomy Backend I don’t see how to register it for the product post type.

    I checked my WordPress categories and taxonomy and I had a WordPress category with the same slug “podcast”. So I changed the WooCommerce taxonomy to “podcast-produkte”, but the problem remains.

    By the way I updated today to WooCommerce 3.3.2, but it didn’t solve my problem.

    Cheers!

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @devcri,

    Sorry if I got this even more complicated than necessary! ?? I noticed this in your last message:

    > it is the default woocommerce taxonomy page (not using a shortcode. And it is not a woocommerce category)

    As far as I understand it, the page having troubles is not a category page, but a default page for a custom taxonomy created in WooCommerce. Is my understanding correct? If that’s the case can you please explain some more what kind of taxonomy this is, and how it was created? This may probably give us some clue to why this taxonomy page isn’t working.

    Thanks!

    Thread Starter devcri

    (@devcri)

    Hi @madeincosmos,

    your understanding is correct.

    I used the taxonomy found in the WooCommerce menu. I gave it a name, nothing fancy here. And than I added the taxonomy to the WooCommerce products.

    I use WooCommerce on a Multisite, but the plugin is only activated in one of them. I use WordPress in german, if that might be relevant?

    Cheers!

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @devcri Can you confirm if this is still an open issue or if you found a solution?

    Also when you state that used the taxonomy found in the WooCommerce menu, are you referring to Categories and Tags?

    https://cld.wthms.co/bBVSu9

    Thread Starter devcri

    (@devcri)

    @jessepearson Problem is now solved. Must have been one of the WooCommerce Updates that solved it. I was referring to “Tags”.

    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @devcri Great, thank you for confirming ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Unwanted dequeuing of styles and scripts on product category / product taxonomy’ is closed to new replies.