I am creating a shortcode plugin for Bootstrap framework that will go along with my theme. However since this would be released to the plugin, if a users's theme already has Bootstrap.css included, is there a way for me to check this from a plugin?


You might be able to use wp_style_is() to do this:

$style = 'bootstrap';
if( ( ! wp_style_is( $style, 'queue' ) ) && ( ! wp_style_is( $style, 'done' ) ) ) {
    //queue up your bootstrap
    wp_enqueue_style( $style, $path_to_bootstrap, $deps, $ver, $media );

This comes with all the same caveats as @Milo's solution -- it'll only work if the copy of bootstrap.css was registered or enqueued with a handle of bootstrap.


  • Thanks Pat. This does the job. As @Milo suggested will have to show some warning/notice too. But this is great. – Harish Chouhan Jun 28 '13 at 7:14

There's no bulletproof way of doing this, as a theme developer could add the bootstrap.css file directly to a theme file, or enqueue it under any number of handles, or rename the css file to something else.

You could check the $wp_styles global for bootstrap in a handle or filename, but this may fail (as noted above) or give you a false positive if bootstrap happens to be in a handle or file unrelated to your bootstrap. It's also possible to build custom versions of bootstrap, so even if you did locate it, it may not contain all of the styles it's assumed to contain.

Here's a quick example of peeking into the enqueued styles:

function wpa_inspect_styles(){
    global $wp_styles;
    var_dump( $wp_styles );
add_action( 'wp_enqueue_scripts', 'wpa_inspect_styles', 9999 );

Probably the best option, in my opinion, is to do some cursory checking and inform the user that you may have detected bootstrap in their theme, enqueue the file by default, and provide an option to disable the stylesheet.

  • Thanks Mila. Showing a user a message as you suggested seems to be a great way to be sure. – Harish Chouhan Jun 28 '13 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.