skip to Main Content

I am building a custom webshop and I am trying to remove the photoswipe style documents but I can’t seem to get rid of them, I tried a couple of "solutions" that I found online but they are not working. This is what I tried so far in the functions.php:

remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-slider' );

and

add_filter( 'woocommerce_enqueue_styles', 'wpf_dequeue_styles' );
function wpf_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['photoswipe-css'] );
unset( $enqueue_styles['photoswipe-default-skin-css'] );
return $enqueue_styles;
}

and

wp_dequeue_script('photoswipe-css');
wp_dequeue_script('photoswipe-default-skin-css');

Can someone help me finding the solution? I don’t have any images in my webshop so I do not need these scripts.

2

Answers


  1. You can remove_theme_support using after_setup_theme action hook.

    add_action( 'after_setup_theme', 'remove_photoswipe_css', 11 ); 
    function remove_photoswipe_css() {
        remove_theme_support( 'wc-product-gallery-zoom' );
        remove_theme_support( 'wc-product-gallery-lightbox' );
        remove_theme_support( 'wc-product-gallery-slider' );
    }
    

    You can wp_dequeue_style using wp_enqueue_scripts action hook.

    add_action( 'wp_enqueue_scripts', 'dequeue_photoswipe_css', 11 );
    function dequeue_photoswipe_css() {
        wp_dequeue_style( 'photoswipe-css' );
        wp_dequeue_style( 'photoswipe-default-skin-css' );
    }
    
    Login or Signup to reply.
  2. If anyone is still looking for the answer to this then the correct code would be :

    add_action( 'wp_enqueue_scripts', 'dequeue_photoswipe_css', 99);
    function dequeue_photoswipe_css() {
        wp_dequeue_style( 'photoswipe' );
        wp_dequeue_style( 'photoswipe-default-skin-css' );
        wp_dequeue_script( 'photoswipe-ui-default' );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search