Selectively dequeue Bootstrap on certain pages such as the WooCommerce shop page

With some themes such as Divi there are stylesheet conflicts with the Bootstrap styles normally loaded by Toolset. You can update the settings so that Toolset doesn’t load Bootstrap, but this may not be an option if you rely on it on certain pages, e.g. where you add CRED forms.

You can selectively remove Bootstrap on particular pages. In this sample code the Bootstrap stylesheet and script files are dequeued on the WooCommerce shop page (the product archive):

/**
 * Don't enqueue Bootstrap on WC Products archive
 */
function dequeue_bootstrap(){

  if ( is_post_type_archive( 'product' ) ) {


    // dequeue Bootstrap CSS
    function dequeue_bootstrap_css(){
      wp_dequeue_style( 'toolset_bootstrap_styles' );
      wp_dequeue_style( 'toolset_bootstrap_4' );
    }
    add_action( 'wp_print_styles', 'dequeue_bootstrap_css' );

    // dequeue Bootstrap JS 
    function dequeue_bootstrap_js(){
      wp_dequeue_script( 'toolset_bootstrap' );
      wp_dequeue_script( 'toolset_bootstrap_4' );
    }
    add_action( 'wp_print_scripts', 'dequeue_bootstrap_js' );    

  }

}
add_action( 'wp_enqueue_scripts', 'dequeue_bootstrap', 100 );

(Updated for BS4)


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Beda Schmid
4 years ago

Update for Bootstrap 4:
The script and style handles for BS 4 are both ‘toolset_bootstrap_4’, so you should dequeue style ‘toolset_bootstrap_4’ and dequeue script ‘toolset_bootstrap_4’ as well to cover 3 and 4.
(By Christian Cox)