Skip Navigation

[Resolved] Apply Bootstrap To Specific Pages Using Toolset

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 4 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1440395

Tell us what you are trying to do?
I'd like to apply the bootstrap grid to only pages that are using toolset. The grid is conflicting with some css on my current theme. (Buddyboss Theme)
Is there any documentation that you are following?
No
Is there a similar example that we can see?
No
What is the link to your site?
tidesofwar.net

#1441287

Hello, I have a custom code snippet that will help dequeue the Bootstrap library on specific post types or pages, but I don't have a snippet that detects whether or not Toolset is used on a specific page. In some cases it's not possible to know when the page header is constructed. If you can tell me a specific post type or post ID you want to exclude from Bootstrap, I might be able to help customize a script for your site.

// example - dequeue bootstrap on WooCommerce Product archive
function dequeue_bootstrap(){

  if ( is_post_type_archive( 'product' ) ) {


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

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

  }

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

Hey Christian,
Thanks for the reply.

I'd like the bootstrap to only be loaded on my post types "Twitch Channels". The reason is because when I load boostrap sitewide, it breaks my photo gallery grid that is using similar css classes.

My site is at hidden link and toolset is running on hidden link and the individual channels are the posts.

The photo grid is at this url: hidden link

Thanks for your help with this.

#1443261

Okay sure, please use this code snippet to dequeue bootstrap 3 and 4 everywhere except the Twitch Channel posts:

function dequeue_bootstrap_except_twitch_channels(){

  if ( get_post_type() != 'twitch-channel' && !is_admin()  ) {

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

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

  }

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

Let me know if this does not fully dequeue the styles and scripts as needed and I can take a closer look.

#1443271

Hi Christian,

Thanks so much! That seems to have fixed the css conflict I had. In the future if I wanted to add any additional post types, can I do that with this code?

#1444685

In the future if I wanted to add any additional post types, can I do that with this code?
Here is a small update to make it more flexible:

function dequeue_bootstrap_except_twitch_channels(){
  // a comma-separated list of post type slugs where you want to include Bootstrap
  $cpts = array( 'twitch-channel' );
  if ( !in_array( get_post_type() , $cpts) && !is_admin()  ) {
 
    // dequeue Bootstrap CSS
    function dequeue_bootstrap_css(){
      wp_dequeue_style( 'toolset_bootstrap_4' );
      wp_dequeue_style( 'toolset_bootstrap_styles' );
    }
    add_action( 'wp_print_styles', 'dequeue_bootstrap_css' );
 
    // dequeue Bootstrap JS
    function dequeue_bootstrap_js(){
      wp_dequeue_script( 'toolset_bootstrap_4' );
      wp_dequeue_script( 'toolset_bootstrap' );
    }
    add_action( 'wp_print_scripts', 'dequeue_bootstrap_js');
 
  }
 
}
add_action( 'wp_enqueue_scripts', 'dequeue_bootstrap_except_twitch_channels', 100 );

You can modify the $cpts array to include a comma-separated list of post type slugs. This is how the $cpts array definition would look with two more custom post types:

$cpts = array( 'twitch-channel', 'cpt-slug-1', 'cpt-slug-2' );
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.