Disable / enable on specific pages (including disabling JS and CSS files)

[ad_1]

Hi Jory,

I’ve attempted setting up a function to disable the OCS on various pages. The code I came up with is:

function disable_off_canvas_sidebar_on_non_shop_pages() {
    if ( function_exists( 'is_woocommerce' ) && ! ( is_shop() || is_product_category() || is_product_tag() && ! ( in_array( 'garden-store', explode( '/', get_page_uri() ) ) ) ) ) {
        add_filter( 'ocs_is_sidebar_enabled', '__return_false' );
        wp_dequeue_script( 'slidebars' );
        wp_dequeue_script( 'off-canvas-sidebars' );
        wp_dequeue_script( 'ocs-fixed-scrolltop' );
        wp_dequeue_script( 'fastclick' );

        wp_dequeue_style( 'off-canvas-sidebars' );
        wp_dequeue_style( 'slidebars' );
    }
}
add_action( 'wp_enqueue_scripts', 'disable_off_canvas_sidebar_on_non_shop_pages' );

This is successfully preventing the sidebar HTML from loading, but the OCS related JS and CSS is still loading. I also tried disabling with with remove_action in case the action function is what you used for loading it, but got the same result (no change).

I’ve tried numerous other approaches to the code, but it seems I’m unable to prevent the JS and CSS loading.

I’m obviously overlooking something.

What would you suggest?

Thank you,

Jonathan

  • This topic was modified 4 hours, 39 minutes ago by inspired888.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer